← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber SWE interview, coding round, one graph problem the whole time. Pretty standard stuff if you've done leetcode graph problems before, but the pressure of actually explaining your reasoning out loud is a different beast.

Questions Asked (1)

Q1

Given a list of courses and their prerequisites represented as directed edges in a graph, determine whether it's possible to complete all courses (i.e., detect if the graph contains a cycle).

Algorithms & Data Structures
Author's notes

I went with BFS topological sort because I always fumble the visited-state tracking in DFS under pressure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses and prerequisites as a directed graph, then determine if it contains a cycle. Use either Kahn's algorithm (BFS-based topological sort) or DFS with recursion stack to detect cycles. Explain the chosen method, its time and space complexity, and how it applies to course scheduling.

Pro tip: Mention that this is essentially topological sorting and that both Kahn's algorithm and DFS are acceptable, but Kahn's is often preferred for its iterative nature and easy cycle detection. Also, discuss how to handle large inputs and potential follow-ups like returning a valid order.

1. Clarify the problem

Confirm that the input is a list of prerequisite pairs (edges) and that we need to determine if all courses can be completed, i.e., if the graph is a DAG. Ask about constraints like number of courses, edge cases (empty list, self-loops), and expected output format.

2. Choose an algorithm

Select either Kahn's algorithm (BFS with in-degree tracking) or DFS with cycle detection. Explain the trade-offs: Kahn's is iterative and naturally detects cycles when processed nodes < total nodes; DFS uses recursion stack but may risk stack overflow for large graphs.

3. Outline the algorithm

For Kahn's: compute in-degrees, enqueue nodes with in-degree 0, process until queue empty, count processed nodes. For DFS: perform DFS, track visited and recursion stack, if a node is revisited in the current stack, a cycle exists.

4. Analyze complexity

State that both approaches run in O(V + E) time and O(V + E) space, where V is number of courses and E is number of prerequisites. Mention that this is optimal for graph traversal.

5. Discuss edge cases and extensions

Address edge cases: no prerequisites (return true), self-loop (return false), disconnected graph. Mention extensions: returning a valid course order, handling multiple prerequisites, or parallel courses.

Key Points to Mention

  • Graph representation: adjacency list for efficiency
  • Cycle detection via topological sorting (Kahn's algorithm) or DFS with recursion stack
  • Time and space complexity: O(V + E)
  • Handling disconnected graphs and self-loops
  • Comparison of BFS vs DFS approaches and when to use each
  • Potential follow-up: return a valid course order (topological sort)

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