Depots That Cannot Reach the Central Hub on One-Way Roads
Last updated: November 29, 2026
Quick Overview
Given a directed road graph between depot ids and a hub id, return the sorted list of depots that have no directed path to the hub, so operations can flag them for rerouting.
Uber
November 29, 20260
0
0 solved
Given a directed road graph between depot ids and a hub id, return the sorted list of depots that have no directed path to the hub, so operations can flag them for rerouting.
Uber Freight and Eats logistics both depend on every depot being able to send vehicles to a hub. The phone screen checks that you avoid one search per depot by reversing the edges and running a single BFS from the hub.
What the Interviewer Expects
- Notice that many sources to one target means one search on the reversed graph
- Build the reverse adjacency list
- BFS or DFS from the hub
- Return depots not visited, in sorted order
- Mention O(V + E) cost
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if you also need depots the hub cannot reach (outbound)?
- How would you find the minimum number of new one-way roads to make everything reach the hub?
- How would you keep this answer fresh as road closures stream in?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of depot ids
nodes, directed edges(u, v)meaning a road from u to v, andhub. - Output: sorted list of nodes other than the hub with no path to the hub....
High-Level Design
Checking each depot with its own BFS costs O(V x (V + E)). Instead reverse every edge: a depot can reach the hub in the original graph exactly when the hub can reach it in the reversed graph. One BFS ...