Dsa
Queue
Easy
Out-of-Order Packet Buffer
A network node receives packets for a file. Packets have sequence numbers from 1 to N. Because of network jitter, they arrive out of order. The node must process and print the packet data strictly in order. If it receives a packet but the previous ones are missing, it must buffer it until the gap is filled.
Input: An integer N (total packets). Then N lines each containing an integer (Sequence Number) and a string (Data).
Output: The data strings, one per line, in the correct order (1 to N).
Example:
Input:
3
2 World
1 Hello
3 !
Output:
Hello
World
!
Key concepts
queuehashing
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