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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
reverse graph
BFS
reachability
directed graph
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: list of depot ids nodes, directed edges (u, v) meaning a road from u to v, and hub.
  • 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 ...


Submit Your Answer
Markdown supported