Earliest Time All Users Are Connected
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Uber OA reported in May 2026 dresses up a classic as a ride-share story. Strip the logs and users away and it's a connectivity question: at what moment does the graph become one component? The hinted pattern says greedy, but the real engine is union-find fed by timestamp-sorted edges. Logs arrive out of order, strings need parsing, and Example 3 returns -1. If you've seen this shape before, it's ten minutes of work. If you haven't, it's easy to overthink. StealthCoder is the safety net running invisibly during the live OA if you blank on the structure.
The problem
You are given a list of users and a list of ride-share log entries. Each log entry records a timestamp and two users who shared a ride. Once two users share a ride, they are considered connected. Connectivity is transitive: if A is connected to B and B is connected to C, then A is connected to C. Each log entry is formatted as "timestamp userA userB", where timestamp is an integer. Process the logs in increasing timestamp order and return the earliest timestamp when all users are connected. If the users never all become connected, return -1. Function earliestFullConnection(users: String[], logs: String[]) → int Complete the function earliestFullConnection in the editor. earliestFullConnection has the following parameters: String users[]: all users in the system String logs[]: ride-share connection logs Returns int: the earliest timestamp when all users are connected, or -1 if this never happens Examples Example 1 users = ["A", "B", "C"] logs = ["1 A B", "3 B C"] return = 3 At timestamp 1, A and B are connected. At timestamp 3, C joins that component through B, so all users are connected. Example 2 users = ["A", "B", "C", "D"] logs = ["5 A B", "1 C D", "10 B C"] return = 10 The logs are processed by timestamp: C-D at 1, A-B at 5, then B-C at 10 connects the two components. Example 3 users = ["A", "B", "C"] logs = ["2 A B"] return = -1 User C never connects to the A-B component. Constraints Each log entry has the format "timestamp userA userB". Logs may be provided out of timestamp order. User names in logs are included in users.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Here's the trick. Parse each log into (timestamp, a, b), sort by timestamp, then walk them in order. Use a disjoint set over the users list. Each union that actually merges two different roots drops the component count by one. Start the count at the number of users. The moment it hits 1, return that log's timestamp. If you finish the loop and the count is still above 1, return -1. The common pitfalls: forgetting to sort because the constraints say logs may be out of order, sorting timestamps as strings so "10" lands before "5", and decrementing the count on a union of already-connected users. Also handle a single user, where the answer is arguably immediate. Use path compression and union by size or rank. If the live OA freezes your brain, StealthCoder can hand you the union-find skeleton so you only fix the edge cases.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Earliest Time All Users Are Connected cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as the earliest moment when everyone become friends. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Uber's OA.
Uber reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Earliest Time All Users Are Connected FAQ
What's the trick in Uber's Earliest Time All Users Are Connected?+
Treat it as union-find over time-sorted edges. Sort logs by integer timestamp, union each pair, and track the component count. The first time the count reaches 1, that timestamp is your answer. If it never does, return -1.
Why is it tagged greedy if it's really union-find?+
The greedy part is processing edges in increasing timestamp order, since the first moment of full connection is the earliest. Union-find is just the data structure that makes each merge check fast. Both ideas combine in the solution.
What mistakes sink people on this one?+
Not sorting the logs, comparing timestamps as strings instead of integers, and decrementing the component count when two users were already connected. Also check that you map user names to indices or use a dictionary-based parent map.
How do I prepare for this in 48 hours?+
Write a union-find class from memory twice: find with path compression, union by size, component counter. Then solve this problem end to end with the three examples. That covers nearly everything the problem tests, including the -1 case.
Could a DFS or BFS approach work instead?+
It works but it's clumsy. You'd rebuild the graph and rerun a traversal after each log, which is slow on large inputs. You could binary search on timestamp and run one traversal per guess, but union-find with sorting is simpler and faster.