Question bank › Stack
Dsa Stack Easy

The Heavy Pallet Stacker

A warehouse stacks items on pallets. Each pallet has a maximum weight capacity 'K'. Items arrive in a specific order. You must place an item on the current pallet if its weight, plus the total weight already on the pallet, does not exceed K. If it does, you must start a new pallet. Pallets operate as stacks (LIFO). Input: The first line is an integer K (max capacity). The second line is a space-separated list of item weights. Output: The weight of the top item (the last item placed) on each pallet, in the order the pallets were created. Example: Input: 10 4 5 2 7 1 Output: 5 7 1 (Explanation: Pallet 1: [4, 5] (sum 9). Pallet 2: [2, 7] (sum 9). Pallet 3: [1] (sum 1). Top items: 5, 7, 1.)

Key concepts

stackgreedysimulation

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.