Dsa
Heap
Easy
The Score-Based Buffer
A network buffer has a maximum capacity C. Each incoming message has an alphanumeric ID and a priority score. If the buffer is full and a new message arrives, you must evict the message currently in the buffer with the LOWEST priority score. If multiple messages share the same lowest score, evict the one that arrived earliest. If the buffer is not full, simply add the message. After processing all N messages, print the IDs of the messages remaining in the buffer, sorted alphabetically.
Example:
C=2. Messages: (A, 10), (B, 20), (C, 15).
- A added.
- B added.
- C arrives. Lowest score is A (10). A is evicted. C added.
Result: B C
Key concepts
heapeviction-policypriority-queue
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