Minimum Plate Collection Time
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Uber's March 2026 OA hands you up to 100,000 plates on a grid and asks for the minimum seconds to collect them all. That input size kills any pairwise comparison, since 10^5 plates means about 5 billion pairs. The real task is counting connected components, and the trick is building the connections without ever comparing every pair. If you've got an invite and 48 hours, learn this shape now. StealthCoder is the safety net on the live OA if your mind goes blank on the grouping step, but the idea is short enough to hold in your head.
The problem
You are given n plates placed on a 2D plane. Plate i is at coordinate (x[i], y[i]). Two plates are connected if they lie in the same row or the same column and the distance between them is at most d. Connectivity is transitive: if plate a is connected to plate b, and plate b is connected to plate c, then collecting one of them collects all plates in that connected component during the same second. You may choose one uncollected plate per second. Return the minimum number of seconds required to collect all plates. Function getMinTime(n: int, d: int, x: int[], y: int[]) → int Examples Example 1 n = 3 d = 1 x = [0, 2, 1] y = [0, 1, 2] return = 3 No pair of plates lies in the same row or column within distance 1, so all three plates are separate connected components. Constraints 1 <= n <= 10^5 0 <= d <= 10^9 0 <= x[i], y[i] <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
The answer is the number of connected components. One pick per second wipes out a whole component, so the minimum time equals the component count. Use union-find. Group plates by row (same x) and sort each group by y. Then union only adjacent plates in sorted order whose gap is at most d. Transitivity covers the rest, because if a and c are within d through b, the chain of adjacent unions links them. Do the same for columns (same y), sorting by x. That gives O(n log n) total. The common pitfall is comparing all pairs, which times out at 10^5. Another is unioning non-adjacent plates, or forgetting d = 0, where only identical coordinates connect. Duplicate coordinates are also worth handling. Count the distinct roots at the end. If you blank on the grouping, StealthCoder can surface the union-find skeleton live.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Minimum Plate Collection Time 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Uber's OA.
Uber reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Plate Collection Time FAQ
What's the trick in Minimum Plate Collection Time?+
Collecting one plate collects its whole connected component, so the answer is the number of components. Build them with union-find by sorting plates within each row and each column and linking only neighbors whose gap is at most d.
Why can't I just compare every pair of plates?+
With n up to 10^5, all pairs is roughly 5 billion checks, which will time out. Sorting within each row and column and linking only adjacent plates gives the same connectivity in O(n log n).
Do I need to union non-adjacent plates in a row?+
No. If plate a connects to c through b, the adjacent links a-b and b-c already put them in one component. If the gap between neighbors exceeds d, no plate further along can bridge it, so you skip it.
What edge cases should I test for this Uber OA problem?+
Test d = 0, where only plates at identical coordinates connect. Test n = 1, which returns 1. Test duplicate coordinates, a long row chain with every gap exactly d, and the sample where no two plates share a row or column, returning 3.
How do I prepare for this in 48 hours?+
Write a union-find with path compression from memory, then practice grouping points by a key using a hash map and sorting each group. Run the sample by hand. That covers the whole problem, and it's a common connected-components pattern.