← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Phone screen at Uber for a SWE role, one algorithmic question on service dependency ordering. The interviewer pushed hard on complexity analysis and apparently that's where a lot of candidates slip up.

Questions Asked (1)

Q1

Given a service dependency graph and a target service, return a valid build order that includes the target and all of its transitive dependencies. Follow-up: what if the graph contains cycles?

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

The core problem is basically course schedule, so I had seen it before.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the dependency graph as a directed graph where edges point from a service to its dependencies. Use DFS with memoization to collect all transitive dependencies of the target, then topologically sort the subgraph to produce a valid build order. For cycles, detect them during DFS and either report an error or break cycles by ignoring back edges, depending on requirements.

Pro tip: Clarify upfront whether the build order should be deterministic (e.g., alphabetical for ties) and whether cycles are considered errors or should be handled gracefully. This shows you think about real-world build systems and edge cases.

1. Clarify requirements and assumptions

Ask if the graph is directed, if cycles are possible, and what to do if cycles exist. Confirm whether the output should include only the target and its dependencies or also unrelated services.

2. Collect transitive dependencies

Perform a DFS or BFS from the target service to find all reachable nodes (dependencies). Use a visited set to avoid infinite loops in cyclic graphs.

3. Topologically sort the subgraph

Apply Kahn's algorithm or DFS-based topological sort on the induced subgraph of collected nodes. Ensure dependencies appear before dependents in the order.

4. Handle cycles

If a cycle is detected, decide whether to throw an error, break the cycle by removing an edge, or return a partial order. Explain the trade-offs of each approach.

5. Analyze complexity and edge cases

State time and space complexity (O(V+E)). Discuss edge cases: target not in graph, self-loop, disconnected components, and multiple valid orders.

Key Points to Mention

  • Graph representation: adjacency list for efficient traversal
  • DFS with visited set to collect dependencies and detect cycles
  • Topological sort algorithms: Kahn's (BFS) vs DFS-based
  • Cycle detection using recursion stack or in-degree counting
  • Handling cycles: error vs. break cycles vs. partial order
  • Time and space complexity: O(V+E) for traversal and sort
  • Deterministic ordering: sorting neighbors for consistent output

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.