← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE interview with a graph connectivity problem that started clean and then got messy fast once the follow-up landed. The core question was doable but the block-events extension is where things got real.

Questions Asked (2)

Q1

You're given a time-ordered log of Uber rider events. Each event records two riders sharing a ride, which creates an undirected connection between them. Two riders are connected if any path of shared rides links them transitively. Find the earliest timestamp at which all riders in the log become part of a single connected component. Return -1 if it never happens.

Algorithms & Data Structures
Author's notes

Pretty much a union-find problem once you see it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model riders as nodes in an undirected graph and process events in chronological order, using a Union-Find (Disjoint Set Union) data structure to efficiently track connected components. After each union, check if the number of components has reduced to 1; if so, return the current timestamp. If all events are processed without reaching a single component, return -1.

Pro tip: Mention that you would first extract all unique riders to initialize the Union-Find, and use path compression and union by rank to achieve near-constant time per operation. Also, clarify edge cases like duplicate events or self-loops (though unlikely) and ensure the solution handles large logs efficiently.

1. Parse and Extract Unique Riders

Read the log and collect all unique rider IDs to determine the total number of riders. Initialize a Union-Find structure with each rider as a separate component.

2. Process Events Chronologically

Iterate through the events in the given time order. For each event, perform a union operation on the two riders if they are not already in the same component.

3. Track Component Count

Maintain a counter for the number of connected components, starting from the total number of riders. Decrement it each time a union successfully merges two distinct components.

4. Check for Single Component

After each union, if the component count becomes 1, return the timestamp of the current event. If the loop finishes without reaching 1, return -1.

Key Points to Mention

  • Union-Find (Disjoint Set Union) data structure with path compression and union by rank for near O(α(n)) time per operation.
  • Time complexity: O(E α(V)) where E is number of events and V is number of riders, which is effectively linear.
  • Space complexity: O(V) for the Union-Find parent and rank arrays.
  • Handling of edge cases: no events, all riders already connected initially (if any), or never connected.
  • The importance of processing events in chronological order to find the earliest timestamp.
  • Potential optimization: early termination once all riders are connected.

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

Q2

Follow-up: the log can now also contain block events, where rider X blocks rider Y and their direct connection is removed from that timestamp onward, even if they shared a ride earlier. How do you modify your approach to still find the earliest time all riders are connected, accounting for edges being both added and removed over time?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I kind of stalled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a dynamic connectivity problem where edges are added and removed over time, and we need the earliest timestamp when the graph becomes connected. Use a segment tree over time with rollback DSU to process intervals of edge existence, or if the graph is small, simulate each timestamp and run a connectivity check. Discuss trade-offs between offline and online approaches, and how to handle the removal of edges efficiently.

Pro tip: Mention that edge removals make incremental DSU insufficient, so you need a rollback DSU or a fully dynamic connectivity data structure; showing awareness of these advanced techniques demonstrates depth. Also, clarify assumptions about the log format and whether queries are offline or online.

1. Clarify problem constraints

Ask about the size of the log, number of riders, frequency of block events, and whether we need to answer a single query or multiple queries. Determine if the solution can be offline or must be online.

2. Model edges with lifetimes

Convert each ride and block event into an interval during which an edge exists. For a ride, the edge exists from the ride timestamp until a block event removes it (or indefinitely if no block). For a block, the edge is removed from that timestamp onward.

3. Choose a dynamic connectivity approach

For offline processing, use a segment tree over time where each edge interval is added to O(log T) nodes, then DFS with a rollback DSU to maintain connectivity. For online or small graphs, simulate each timestamp and recompute connectivity, or use a dynamic connectivity data structure.

4. Find earliest connected timestamp

During the segment tree DFS, at each leaf (timestamp), check if all riders are in one component. The first timestamp where this holds is the answer. Alternatively, binary search on time if connectivity is monotonic (but it's not with removals, so segment tree is better).

5. Analyze complexity and trade-offs

Discuss time and space complexity: segment tree with rollback DSU takes O((E + T) log T) time and O(E log T) space. Compare with naive simulation O(T * (V+E)) and explain why the advanced approach is preferable for large inputs.

Key Points to Mention

  • Dynamic connectivity problem with edge insertions and deletions
  • Rollback DSU (disjoint set union) to support undo operations
  • Segment tree over time to batch edge intervals
  • Offline vs online processing trade-offs
  • Handling of block events that remove edges even if a ride occurred earlier
  • Complexity analysis: O((E + T) log T) time with segment tree + rollback DSU

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