Question bank › Heap
Dsa Heap Easy

Packet Reorder Buffer

A network receiver receives N numbered packets (1 to N) but they arrive out of order. The receiver can only 'process' packet P if all packets from 1 to P-1 have already been processed. Packets that arrive early are stored in a buffer. What is the maximum number of packets stored in the buffer at any one time? Input Format: - The first line contains N. - The second line contains N unique integers from 1 to N, representing the arrival order of packets. Output Format: - A single integer representing the maximum buffer size during the process. Example: Input: 5 1 3 2 5 4 Output: 1 (Explanation: 1 arrives, processed immediately. 3 arrives, buffered (size 1). 2 arrives, 2 and 3 processed. 5 arrives, buffered (size 1). 4 arrives, 4 and 5 processed. Max size was 1.)

Key concepts

heapsequence tracking

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.