← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE interview with a graph theory problem that started straightforward and then got extended mid-session. The follow-up felt like the real test.

Questions Asked (2)

Q1

Given a directed graph of n services with dependency edges, implement a function to detect whether the graph contains at least one cycle. Return true if a cycle exists, false otherwise.

Algorithms & Data Structures
Author's notes

Classic DFS with a recursion stack to track back edges.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (e.g., graph size, whether the graph is mutable) and then propose a cycle detection algorithm such as DFS with recursion stack or Kahn's topological sort. Explain the algorithm step-by-step, analyze time and space complexity, and discuss edge cases like self-loops and disconnected components.

Pro tip: Mention that Kahn's algorithm can also provide a topological order if no cycle exists, which is useful for dependency resolution. Also, note that early termination upon finding a back edge can save time in practice.

1. Clarify requirements and constraints

Ask about graph size, whether it's mutable, and if additional information (like topological order) is needed. This shows you consider practical aspects before coding.

2. Choose an algorithm

Select either DFS with recursion stack or Kahn's algorithm based on constraints. Explain why your choice is suitable (e.g., DFS is simpler for sparse graphs, Kahn's avoids recursion depth issues).

3. Outline the algorithm

Describe the steps: for DFS, track visited and recursion stack; for Kahn's, compute in-degrees and process nodes with zero in-degree. Highlight how cycles are detected.

4. Analyze complexity and edge cases

State time and space complexity (O(V+E) for both). Discuss edge cases: empty graph, self-loops, disconnected components, and large graphs.

5. Discuss optimizations and trade-offs

Mention iterative DFS to avoid stack overflow, early termination, and that Kahn's can return a topological order if no cycle. Compare trade-offs between approaches.

Key Points to Mention

  • DFS with recursion stack: mark nodes as unvisited, visiting, and visited; a back edge to a visiting node indicates a cycle.
  • Kahn's algorithm: repeatedly remove nodes with in-degree zero; if not all nodes are removed, a cycle exists.
  • Time and space complexity: O(V+E) time, O(V) space for both algorithms.
  • Handling disconnected graphs: run the algorithm from each unvisited node.
  • Self-loops are cycles and should be detected.
  • Trade-offs: DFS is simpler but may cause stack overflow; Kahn's is iterative and can produce topological order.

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

Q2

Follow-up: instead of a single dependency list, you now receive multiple separate dependency arrays for the same set of services. Treat the union of all edges as one graph and determine whether any cycle exists. Describe your approach, data structures, and complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where it got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Treat the union of all dependency arrays as a single directed graph and detect cycles using DFS with a recursion stack or Kahn's topological sort. Clarify that duplicate edges are harmless and can be ignored, then analyze complexity in terms of total vertices and total edges across all arrays.

Pro tip: Mention that you would deduplicate edges or use a visited set to avoid redundant work, and note that Kahn's algorithm can also produce a valid build order if no cycle exists—showing you think beyond just detection.

1. Clarify and model the graph

Confirm that each dependency array represents directed edges (e.g., A depends on B means B -> A or A -> B, depending on convention). Define V as the set of unique services and E as the union of all edges across arrays.

2. Choose cycle detection algorithm

Select either DFS with three colors (white/gray/black) or Kahn's topological sort. Explain why both work: DFS detects back edges, while Kahn's detects cycles if not all nodes are processed.

3. Handle duplicates and build adjacency list

Iterate through all arrays, adding edges to an adjacency list. Use a set per node or a global set to deduplicate edges, ensuring O(V + E) space where E is the number of unique edges.

4. Run detection and analyze complexity

Execute the chosen algorithm. State time complexity O(V + E) and space O(V + E), where E is the total unique edges across all arrays. Mention that if arrays are large with many duplicates, deduplication keeps E bounded by V^2.

5. Discuss trade-offs and edge cases

Compare DFS vs Kahn's: DFS is simpler for pure detection, Kahn's gives topological order and can be more intuitive for dependency resolution. Address edge cases: empty arrays, self-loops, disconnected components.

Key Points to Mention

  • Union of edges: treat all dependency arrays as one graph, ignoring duplicates.
  • Cycle detection via DFS with recursion stack (colors) or Kahn's topological sort.
  • Time and space complexity: O(V + E) where V is unique services and E is unique edges.
  • Deduplication of edges to avoid redundant processing and keep E bounded.
  • Trade-offs: DFS vs Kahn's, and how to handle self-loops or disconnected graphs.
  • Practical relevance: detecting circular dependencies in microservices (Uber context).

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