Question bank › Queue
Dsa Queue Hard

Deadline-Driven Reorder Buffer

Data packets 1, 2, 3... are sent over a network but arrive out of order. You have a reorder buffer of fixed size B. 1. You always want to output the 'next' expected packet (starting at 1). 2. If the next expected packet arrives, print it and increment the expected count. Then check if the *new* expected packet is already in the buffer; if so, repeat. 3. If an out-of-order packet arrives (ID > expected), store it in the buffer. 4. If the buffer is full and a new out-of-order packet arrives, you must discard the packet in the buffer with the *lowest* ID to make room, UNLESS the arriving packet itself has a lower ID than everything in the buffer (in which case, discard the arriving packet). Input: B (buffer size), N (packets arriving). Then N packet IDs. Output: Space-separated IDs of packets successfully output in order. Example: Input: 2 5 3 1 4 2 5 Output: 1 2 3 4 5

Key concepts

queuesliding windowsorting

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.