← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE interview with a graph problem that looks straightforward but has a few subtle edges (pun intended). The offline DSU approach is the key insight and they did push on complexity and online query variants.

Questions Asked (1)

Q1

Given an undirected weighted graph and a list of queries of the form (p, q, k), determine for each query whether a path exists from p to q where every edge along the path has weight strictly greater than (or at least) k. Return a boolean per query.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The tricky part is the wording.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the graph's edges as being 'active' only when their weight exceeds k, and process queries offline in descending order of k while incrementally adding edges. Use a Disjoint Set Union (DSU) to maintain connectivity components, answering each query by checking if p and q are in the same component. This yields near-linear time after sorting, which is optimal for large inputs.

Pro tip: Clarify the threshold condition early: 'strictly greater than k' vs 'at least k' changes the edge activation order and can lead to off-by-one bugs. Also mention that if queries are online, you'd need a different structure like a maximum spanning tree with binary lifting, but offline DSU is simpler and faster.

1. Clarify requirements and edge cases

Confirm whether the condition is > k or >= k, and handle cases where p == q (always true if no edges needed) or when k is larger than all edge weights (no edges active).

2. Choose offline processing with DSU

Sort edges by weight descending and queries by k descending. Process queries in order, adding all edges with weight > k (or >= k) to the DSU before answering each query.

3. Implement DSU with path compression and union by rank

Use an efficient DSU to maintain connected components as edges are added. This ensures near-constant time per union/find operation.

4. Answer queries and analyze complexity

For each query, check if find(p) == find(q). The overall time is O(E log E + Q log Q + (E+Q) α(N)), which is efficient for large graphs.

5. Discuss trade-offs and alternatives

Mention that if queries must be answered online, you could build a maximum spanning tree and use binary lifting to answer path-minimum queries, but offline DSU is simpler and faster for batch processing.

Key Points to Mention

  • Offline processing: sort queries and edges to avoid recomputing connectivity for each query.
  • Disjoint Set Union (Union-Find) with path compression and union by rank for efficient connectivity checks.
  • Threshold handling: strictly greater than k vs at least k, and how it affects edge activation.
  • Time complexity: O(E log E + Q log Q + (E+Q) α(N)) and why it's optimal for this problem.
  • Edge cases: p == q, k larger than all edge weights, disconnected graph, multiple queries with same k.
  • Alternative online approach: maximum spanning tree + binary lifting for path minimum queries, with trade-offs.

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