Question bank › Heap
Dsa Heap Easy

Server Lease Manager

A cloud provider has S servers, numbered 1 to S. When a request arrives at 'start_time' with a 'duration', it needs a server. You must assign it the available server with the lowest ID. If no servers are available at 'start_time', the request is dropped. A server becomes available exactly at 'start_time + duration'. Input Format: - The first line contains S (number of servers) and R (number of requests). - The next R lines each contain two integers: 'start_time' and 'duration'. Requests are sorted by start_time. Output Format: - R lines. Each line contains the ID of the server assigned to that request, or -1 if the request was dropped. Example: Input: 2 3 1 5 2 5 6 1 Output: 1 2 1 (Explanation: R1 (1,5) gets S1. R2 (2,5) gets S2. At time 6, S1 is free (1+5=6), so R3 (6,1) gets S1.)

Key concepts

heapscheduling

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.