🧠 Agoda Technical Assessment (Back End) – Problem Breakdown & Solutions Recently, I attempted a Back End Software Engineering assessment that included two interesting problems:
Tree Diameter Variant (Graph / BFS)
REST API Pagination + Filtering
Here’s a breakdown of both problems and the clean engineering approach to solving them.
Problem 1: Special Nodes in a Tree
Problem Summary
Given a tree with n nodes, a node is special if it is an endpoint of any diameter of the tree.
Return a binary array where:
1 → node is special
0 → node is not special
Key Definition
The diameter of a tree is the number of edges in the longest path.
Important detail:
There can be multiple diameter paths. We must mark endpoints of any of them.
🔍 Core Insight
In a tree:
Pick any node → find the farthest node A
From A, find the farthest node B
Distance between A and B = diameter D
Now compute:
distA[i] = distance from A
distB[i] = distance from B
A node is special if:
max(distA[i], distB[i]) == D
Why? Because nodes whose eccentricity equals the diameter are endpoints of some longest path.
⏱ Time Complexity
3 BFS traversals
O(n)
Works up to 105 nodes.
💡 Implementation (Python)
import collections
def isSpecial(tree_nodes, tree_from, tree_to):
if tree_nodes
Problem 2: Best TV Show in a Genre (REST API)
Problem Summary
Use HTTP GET to query:
https://jsonmock.hackerrank.com/api/tvseries
Results are paginated.
Given a genre:
Find all shows containing that genre
Return the show with highest IMDb rating
If tie → return alphabetically smaller name
🔍 Key Requirements
Must iterate all pages (?page=1, ?page=2, …)
Genre is substring match (e.g., "Action" in "Action, Drama")
Handle rating ties properly
⏱ Complexity
O(total_records)
Usually small dataset.
💡 Implementation (Python)
import requests
def bestInGenre(genre):
base_url = "https://jsonmock.hackerrank.com/api/tvseries"
page = 1
best_name = ""
best_rating = -1
while True:
response = requests.get(f"{base_url}?page={page}")
data = response.json()
for show in data["data"]:
if genre in show["genre"]:
rating = show["imdb_rating"]
name = show["name"]
if rating > best_rating:
best_rating = rating
best_name = name
elif rating == best_rating and name = data["total_pages"]:
break
page += 1
return best_name
Engineering Takeaways
1️⃣ Tree Problems
Diameter problems almost always reduce to two BFS/DFS passes.
Endpoint detection is often about eccentricity.
2️⃣ REST API Problems
Always check pagination.
Don’t overcomplicate with sorting.
Track max in single pass.
3️⃣ Interview Strategy Insight
Assessments often test:
Clean algorithm fundamentals
Edge-case awareness
API handling discipline
Time complexity clarity
Final Thoughts
These problems aren’t about memorizing tricks.
They test:
Whether you understand tree properties
Whether you handle pagination carefully
Whether you write production-safe logic
If you're preparing for backend interviews, mastering these fundamentals is essential.
Learn more