Reported October 2024
Googlesimulation

Conveyor Triplet Packaging

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

The edge case that kills most first attempts at this Google OA from October 2024 is consumed items. Mark one wrong and a later anchor grabs a value that's already boxed. Conveyor Triplet Packaging looks like a sorting or greedy problem, but the rules forbid sorting and extra tracking collections. It's a simulation with index order baked in. n is at most 150, so brute force is the intended route. If you blank on the exact tie-breaking, StealthCoder is the safety net that runs invisibly during the live assessment and hands you a working solution.

The problem

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.0
return = [[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.0
return = [[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 items is a finite double.
d is a finite double and d >= 0.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that nothing clever is needed. Loop i from left to right. Skip it if items[i] is NaN. Then scan j from i+1, skipping NaN, and for each j scan k from j+1, skipping NaN. The first (j, k) where all three pairwise differences are at most d is the lexicographically earliest pair. Because j is the outer loop and k the inner, the first hit is automatically earliest. Replace all three with NaN and append [items[i], items[j], items[k]] to the output. The pitfall is checking only the differences from the anchor. You need |items[j]-items[k]| <= d too. Also, NaN comparisons are always false, so don't rely on that. Check with Number.isNaN or the equivalent explicitly. Don't break out of the anchor loop after one box. Cost is O(n^3) worst case, fine for 150. If you freeze on the pairwise check or the mutation order, StealthCoder is the hedge during the live OA.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Conveyor Triplet Packaging 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 passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Conveyor Triplet Packaging FAQ

How hard is Conveyor Triplet Packaging really?+

Easy to medium. The algorithm is a triple nested loop, but the spec is dense. Most lost points come from misreading rules about lexicographic order, consumed items, and the pairwise check, not from hard algorithmic ideas.

What's the trick?+

Nested loops make lexicographic order free. For each live anchor i, iterate j then k in increasing order and take the first valid pair. Mark all three as NaN right away so later anchors skip them.

Do I need to check all three pairs?+

Yes. A triple fits only if every pair is within d. Checking anchor to j and anchor to k isn't enough. You must also verify j to k, otherwise you'll build boxes that violate the rule.

Can I sort to make it faster?+

No. The problem forbids sorting and requires original index order inside each box. With n at most 150, O(n^3) is fine, so there's no need to optimize anyway.

How do I prepare in 48 hours?+

Practice simulation problems with in-place marking and nested index scans. Write this one yourself and test it on both examples, plus an empty array and d = 0. Focus on skipping consumed entries cleanly.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it