← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Uber follow-up round that built on a previous connectivity problem, this time throwing in block constraints that completely break the standard Union-Find approach. Harder than I expected and the complexity discussion at the end got uncomfortable fast.

Questions Asked (2)

Q1

You have an event log with ride-share events and block events between riders. A block means two riders can never be considered connected, even indirectly. Design an algorithm that finds the earliest timestamp at which all riders are connected without violating any block constraint, returning -1 if it's impossible.

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

This is a follow-up to a rider connectivity problem so they expected you to already know the baseline Union-Find solution.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model riders as nodes and ride-share events as edges with timestamps. Sort events by time and process them in order, using a modified union-find that respects block constraints (e.g., by tracking forbidden merges or using a bipartite/colored approach). After each event, check if all riders are in one connected component; return the timestamp when this first happens, or -1 if never.

Pro tip: Clarify upfront whether block constraints are static (known in advance) or dynamic, and discuss the trade-off between pre-processing blocks into a conflict graph versus checking on-the-fly. This shows you think about real-world data variability and scalability.

1. Clarify constraints and assumptions

Ask if block events are known in advance, if they are symmetric, and if connectivity is transitive. Confirm that a block between two riders prevents any indirect connection through others.

2. Model as a graph problem

Represent riders as nodes, ride events as timestamped edges, and block events as forbidden connections. The goal is to find the earliest time when the graph of allowed edges connects all nodes.

3. Design the algorithm

Sort ride events by timestamp. Use a union-find structure that incorporates block constraints, e.g., by maintaining a set of forbidden merges or using a bipartite coloring to ensure no component contains blocked pairs.

4. Handle block constraints efficiently

Pre-process blocks into a conflict graph. When merging two components, check if any node in one is blocked with any node in the other; if so, skip the merge. Optimize by tracking component-level block summaries.

5. Analyze complexity and edge cases

Discuss time/space complexity, worst-case scenarios (e.g., many blocks), and edge cases like disconnected riders, duplicate events, or blocks that make connection impossible.

Key Points to Mention

  • Union-Find (Disjoint Set Union) with path compression and union by rank for efficient connectivity checks.
  • Sorting events by timestamp and processing incrementally to find the earliest connection time.
  • Block constraints as a conflict graph; need to prevent merges that would create a component containing a blocked pair.
  • Potential use of bipartite coloring or component-level block summaries to efficiently check merge validity.
  • Time complexity: O(E log E + E * α(N) + B * something) where E is number of ride events, B is number of blocks; discuss optimizations.
  • Edge cases: no events, all riders already connected, blocks that isolate a rider, and returning -1 when impossible.

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

Q2

Compare the time complexity of your BFS/DFS approach against the Union-Find baseline, and discuss whether offline processing, link-cut trees, or batched recomputation could improve it.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where things got awkward.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly stating the time complexities of your BFS/DFS approach and the Union-Find baseline, including any assumptions about graph size and query patterns. Then analyze whether offline processing, link-cut trees, or batched recomputation can improve performance, considering trade-offs like implementation complexity and constant factors. Conclude with a recommendation based on the specific constraints of the problem.

Pro tip: Don't just list data structures; tie your analysis to the actual problem constraints (e.g., number of queries, graph density) and mention that sometimes a simpler approach with better constants outperforms asymptotically superior but complex structures.

1. State complexities and assumptions

Clearly specify the time complexity of your BFS/DFS approach and the Union-Find baseline, including whether they are per query or for all queries, and any assumptions about graph size, density, or query patterns.

2. Analyze offline processing potential

Discuss whether queries can be processed offline (e.g., sorting queries, using divide-and-conquer) to reduce overall time, and compare the resulting complexity to the online approaches.

3. Evaluate link-cut trees

Explain how link-cut trees can handle dynamic connectivity and path queries in O(log n) amortized time, but note their high implementation complexity and constant factors.

4. Consider batched recomputation

Assess if batching updates and recomputing connectivity periodically (e.g., sqrt decomposition) can offer a practical trade-off between time and implementation effort.

5. Recommend based on constraints

Synthesize the analysis and recommend the best approach for the given problem, justifying your choice with respect to input size, query frequency, and engineering constraints.

Key Points to Mention

  • Time complexity of BFS/DFS: O(V+E) per query, which can be O(Q*(V+E)) for Q queries.
  • Union-Find baseline: O(α(n)) per operation, but may require rebuilding for dynamic updates.
  • Offline processing: can reduce to O((V+E+Q) log V) using techniques like parallel binary search or divide-and-conquer on time.
  • Link-cut trees: O(log n) amortized per operation for dynamic trees, but complex to implement and high constant factors.
  • Batched recomputation: sqrt decomposition can achieve O((V+E) * sqrt(Q)) or similar, balancing simplicity and performance.
  • Trade-offs: consider implementation complexity, constant factors, and whether the problem is static or dynamic.

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