Dsa
Queue
Easy
Sequential Assembly Buffer
Parts arrive on a belt with unsorted integer IDs. They must be packed into boxes in strict sequential order starting from 1 (1, 2, 3...). If the part at the front of the belt is not the next one needed, it is moved to a holding buffer. Every time a part is packed, you must check the holding buffer to see if the next required part is now available there. Print the IDs in the order they are packed.
Example:
Input:
2 1 4 3
Output:
1 2 3 4
Key concepts
queuebuffersorting-simulation
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