Pack Triplets on a Conveyor Belt

Asked at Google · Coding Questions · Difficulty: Medium

Items arrive one at a time on a conveyor belt, and each item has an integer value. As soon as a newly arrived item can be packed together with two items already waiting on the belt so that the three values add up to a fixed target `size`, those three items are packed and leave the belt. Implement a class that processes the arrivals online and reports each packed triplet.

Loading the problem…