Streamed Planar Item Triplets
Updated
Problem statement
Items arrive one at a time. Each item has a two-dimensional integer value [x,y], represented by a row of points in arrival order. Its item ID is its zero-based row index. Equal coordinates still represent different items.
Keep unconsumed items until a group of exactly three fits. For this exercise, assume a group fits only when the Euclidean distance between every pair of its items is strictly less than threshold. A pair at exactly the threshold is excluded.
After each arrival, choose the lexicographically smallest valid triple of available item IDs, written in increasing order, and immediately consume all three items. If no triple fits, retain the new item. Consumed items never become available again. There can be at most one group at an arrival: the preceding state had no fitting triple, so every new fitting triple contains the new item.
Return one row per arrival. The row contains the three consumed IDs if a group forms, or an empty array if it does not. This finite batch simulates a class method that stores one arriving item and immediately returns a fitting group. Do not process future arrivals early or flush unmatched items into a group at the end.
For two item IDs i and j, the exact compatibility test is (points[i][0] - points[j][0])^2 + (points[i][1] - points[j][1])^2 < threshold^2. At threshold 0, no pair fits, even at equal coordinates.
Function
packagePointArrivals(points: int[][], threshold: int) → int[][]Examples
Example 1
points = [[0,0],[1,0],[0,1],[10,10],[11,10],[10,11]]threshold = 2return = [[],[],[0,1,2],[],[],[3,4,5]]The first three arrivals fit and are consumed at ID 2. The later three fit at ID 5; earlier items cannot be reused.
Example 2
points = [[0,0],[3,0],[1,0],[2,0]]threshold = 3return = [[],[],[],[0,2,3]]The first three cannot form a group because IDs 0 and 1 are exactly distance 3 apart. At ID 3, the earliest fitting triple is [0,2,3].
Example 3
points = [[3,4],[3,4],[3,4],[3,4]]threshold = 1return = [[],[],[0,1,2],[]]The first three identical coordinates represent distinct items and form a group. The fourth arrival remains alone.
Constraints
- For this exercise, assume
0 <= points.length <= 300. - Every row contains exactly two integers; for this exercise, assume
-10^6 <= x, y <= 10^6. - For this exercise, assume
0 <= threshold <= 10^6. - Arrival order may be arbitrary, and duplicate coordinates are allowed.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- HTTP Request RedirectionAmazon · OA
- Rectangle Fit QueriesZipRecruiter · OA
- Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
- Spiral MatrixAthenahealth · ONSITE INTERVIEW
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEW
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEW
- Tax Calculation with Year and Filing RulesGusto · ONSITE INTERVIEW
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEW
- Digit-Coded Card ValidationCapital One · ONSITE INTERVIEW
- Instant-Runoff Voting WinnerWise · ONSITE INTERVIEW