Dsa
Heap
Easy
The Battery-Aware Fleet
You manage N drones, each with a specific battery percentage. There are M missions, each costing a certain percentage of battery. For each mission, you MUST assign the drone currently having the highest battery. If the highest battery is less than the mission cost, that mission is skipped entirely. If multiple drones have the same maximum battery, use any one. After all missions, print the final battery levels of all drones in descending order.
Example:
N=2 drones [100, 80]. M=2 missions [30, 60].
- Mission 1 (cost 30): Assigned to drone 100. New battery: 70.
- Mission 2 (cost 60): Assigned to drone 80 (since 80 > 70). New battery: 20.
Result: 70 20
Key concepts
heapgreedymax-heap
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