Dsa
Queue
Easy
The Delivery Truck Batcher
A warehouse uses a conveyor belt to load packages into a delivery truck. The truck has a strict weight capacity. Packages arrive in a specific order and must be processed in that order. The truck will take as many packages as it can without exceeding its weight limit. Once the next package in the queue would exceed the current truck's capacity, the truck departs, and a new empty truck arrives. Print the packages loaded into each truck, with trucks separated by ' | '.
Example:
Input:
10
4 5 2 7 1
Output:
4,5 | 2,7 | 1
Key concepts
queuesimulationgreedy
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now