Status: Screening Round
Duration: 45 minutes (5 mins intro + 15 mins explanation + 25 mins coding)
Problem Statement (As I Remember)
There are N cities in a town, and some of them are connected with roads. Each road takes a certain number of hours to travel. You're given the road network as a list of edges:
edges = [ [u, v, h], ... ]
Where:
u and v are city indices.
h is the time in hours to travel between u and v.
You are also given:
Goal
For each query (d, H), find the maximum number of cities you can visit on the shortest path from s to d within H hours.
Example:
Let's say:
source = 2
One of the shortest paths to destination = 10 is:
2 → 4 → 9 → 12 → 15 → 18 → 10, and the shortest distance is 50 hours.
You can precompute something like:
cities_visited_by_time = [2, 4, 9, 12, 15, 18]
This means:
City 1 is reached at 2nd hour,
City 2 at 4th hour,
...
For a query with H = 14, you can do a binary search (lower/upper bound) on cities_visited_by_time to find how many cities are visited within 14 hours.
My Approach:
Dijkstra’s Algorithm:
From the source city s, precompute shortest paths to all other cities.
While building the shortest path to a destination, maintain a list of cumulative hours when each city is reached (in path order).
Preprocessing:
For each node, store the shortest path and the hours at which each city is visited on that path.
Query Processing:
For a given (destination, H), use binary search (lower bound) on the cumulative time list to find how many cities were visited within H hours.
Time Complexity:
Dijkstra: O(N log N + E log N)
[IMP] Final Thoughts
I gave my best during the interview. The problem was interesting and implementation-heavy under time constraints, but I felt confident in my approach and communication.
However, despite following up 3–4 times, I never received any feedback — neither a rejection nor a selection.
Honestly, this part was disappointing.
As candidates, we invest a lot of time preparing and genuinely care about the process, so some form of closure would go a long way.