← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE interview with a graph traversal problem disguised as a build system question. The API-driven discovery angle made it trickier than a plain topological sort.

Questions Asked (1)

Q1

You have a function get_dependencies(package) that returns the direct dependencies of a package. Given a target package, return a valid build order for it and all its transitive dependencies, discovering the graph only by calling this API. Handle cycles, missing packages, and duplicate dependencies.

Algorithms & Data StructuresAPI & IntegrationsSystem Design
Author's notes

This took me a minute to even parse correctly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use depth-first search (DFS) with a temporary mark to detect cycles and a permanent mark to avoid revisiting nodes, building the order in post-order. Handle missing packages by treating them as leaves or raising an error, and deduplicate dependencies by using a set. Return the reversed post-order list as the build order.

Pro tip: Mention that you would cache results of get_dependencies to avoid repeated API calls, and discuss how to handle cycles by either breaking them or reporting an error, depending on requirements.

1. Clarify requirements and edge cases

Ask about expected behavior for cycles (error vs. break), missing packages (ignore vs. error), and whether the build order should include the target package itself.

2. Design the graph traversal

Use DFS with three states: unvisited, visiting (in current path), and visited (fully processed). This detects cycles and avoids duplicate work.

3. Implement the DFS

For each package, mark it as visiting, recursively process its dependencies (from get_dependencies), then mark it as visited and add it to the result list. If a dependency is already visiting, a cycle is detected.

4. Handle missing packages and duplicates

If get_dependencies returns a package that doesn't exist, either treat it as a leaf or raise an error. Use a set to deduplicate dependencies before processing.

5. Return the build order

After DFS completes, reverse the result list to get a valid topological order where dependencies come before dependents.

Key Points to Mention

  • Topological sorting via DFS post-order
  • Cycle detection using a 'visiting' state
  • Deduplication of dependencies with a set
  • Handling missing packages gracefully
  • Caching get_dependencies results to optimize API calls
  • Time and space complexity: O(V + E) where V is packages and E is dependency edges

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