Conveyor Triplet Packaging
Updated
Problem statement
Items arrive on a conveyor as the finite double array items. Package items into boxes of exactly three. A triple fits if the absolute difference between every pair of values is at most d.
Process anchors from left to right. For the earliest unpacked anchor index i, choose the lexicographically earliest pair of later unpacked indices (j, k) that forms a fitting triple. If no such pair exists, leave the anchor unpacked and continue.
Return completed boxes in anchor order. Values inside each box must retain their input-index order, and unpacked items are omitted. Do not sort the array or allocate an auxiliary collection to track consumed items. You may mutate items by replacing consumed entries with NaN; output storage does not count as auxiliary space.
Function
packageTriplets(items: double[], d: double) → double[][]Examples
Example 1
items = [1.0,11.0,12.0,13.0,2.0,3.0]d = 3.0return = [[1.0,2.0,3.0],[11.0,12.0,13.0]]Anchor 1.0 first fits with the later values 2.0 and 3.0. The earliest remaining anchor is then 11.0, which fits with 12.0 and 13.0.
Example 2
items = [0.0,10.0,11.0,12.0,1.0,2.0,20.0]d = 2.0return = [[0.0,1.0,2.0],[10.0,11.0,12.0]]The search keeps original indices rather than sorted value order. The final value 20.0 cannot complete a box and is omitted.
Constraints
0 <= items.length <= 150- Every entry of
itemsis a finite double. dis a finite double andd >= 0.
More Google Phone Screen questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Climb Detection with Recoverable DipsStrava · PHONE SCREEN
- Evenly Schedule Vehicle InspectionsAmazon · PHONE SCREEN
- Experiment Bucket Allocation and RebalancingPinterest · PHONE SCREENPinterest interview questions
- Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
- Generate an Optimal Portfolio Trading ReportPoint72 · PHONE SCREENPoint72 interview questions
- Future-Aware Cache EvictionBenchling · PHONE SCREENBenchling interview questions
- Maximize Circular Rover TravelBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Priority, Expiration, and LRU EvictionTesla · PHONE SCREENTesla interview questions
- Text JustificationUber · PHONE SCREENUber interview questions
- Find GPU Capacity and Drain a NodeTogether AI · PHONE SCREEN