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.
Examples
01 · 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^50 <= d <= 10^90 <= x[i], y[i] <= 10^9
More Uber problems
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
public int getMinTime(int n, int d, int[] x, int[] y) {
// write your code here
}n3
d1
x[0, 2, 1]
y[0, 1, 2]
expected3
sign in to submit