Earliest Moment Every Driver Joins One Radio Mesh
Last updated: November 29, 2026
Quick Overview
Driver devices form links over time, each log entry (timestamp, a, b) connecting two of n drivers; return the earliest timestamp after which all drivers are in one connected group, or -1 if that never happens.
Uber
November 29, 20260
0
0 solved
Driver devices form links over time, each log entry (timestamp, a, b) connecting two of n drivers; return the earliest timestamp after which all drivers are in one connected group, or -1 if that never happens.
Offline-first features in Uber's driver app (for example, sharing incident alerts at events with poor coverage) could rely on device meshes. The phone screen checks that you sort by time, union as you go, and stop when the component count reaches one.
What the Interviewer Expects
- Sort link events by timestamp
- Track the number of components, decrementing on successful unions
- Return the timestamp of the union that makes the count one
- Return -1 if never connected
- Handle n = 1
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if links also expire after some time?
- Return the time at which the largest group first exceeds half of all drivers
- How would you answer many 'are a and b connected at time t' queries?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
ndrivers0..n-1,logslist of(t, a, b)in any order. - Output: smallest
tat which all drivers are connected;-1if never;0conventionally forn = 1(already connected), co...
High-Level Design
Sort logs by time. Start with n components. For each link, if union(a, b) merges two different components, decrement the count. The moment the count hits 1, that log's timestamp is the answer, sin...