← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber phone screen, pretty much one algorithmic problem the whole time. The problem was clever enough that I almost missed the key insight until I started drawing it out.

Questions Asked (1)

Q1

Given a chronological log of ride-share events where each event records two riders who shared a ride, find the earliest timestamp at which all riders in the system are part of a single connected component. Return -1 if this never happens.

Algorithms & Data Structures
Author's notes

My first instinct was BFS per timestamp which would have been a mess.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as dynamic connectivity: process events in chronological order, union the two riders in each event, and track the number of connected components. The earliest timestamp when the component count drops to 1 is the answer; if it never does, return -1.

Pro tip: Clarify assumptions upfront: whether rider IDs are known in advance, if events are sorted, and whether the graph is guaranteed to eventually connect. This shows you think about edge cases and data constraints before coding.

1. Clarify requirements and constraints

Ask about input format, rider ID range, event ordering, and what 'all riders' means (e.g., all riders seen in events). Confirm that events are chronological and that we need the earliest timestamp.

2. Choose data structures

Use Union-Find (Disjoint Set Union) with path compression and union by rank for near-constant time operations. Maintain a count of connected components, initialized to the number of unique riders.

3. Process events and track components

Iterate through events in order. For each event, union the two riders; if they were in different components, decrement the component count. After each union, check if the count equals 1.

4. Return result or -1

If the component count becomes 1 at some event, return that event's timestamp. If all events are processed and the count is still >1, return -1.

5. Analyze complexity and edge cases

Discuss time complexity O(E α(N)) and space O(N). Handle edge cases: no events, single rider, disconnected riders, duplicate events, and riders appearing only once.

Key Points to Mention

  • Union-Find (Disjoint Set Union) with path compression and union by rank
  • Maintaining a running count of connected components
  • Time complexity: O(E α(N)) where E is number of events and α is inverse Ackermann
  • Space complexity: O(N) for parent and rank arrays
  • Edge cases: empty log, single rider, never fully connected
  • Early termination when component count reaches 1

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