Dsa
Heap
Easy
Load Balanced Clusters
You have S servers, indexed 0 to S-1. Initially, all have 0 load. You receive T tasks, each with a 'load value'. Each task must be assigned to the server that currently has the minimum total load. If multiple servers have the same minimum load, assign the task to the server with the smallest index. After all tasks are assigned, what is the final load on each server?
Input Format:
- The first line contains S and T.
- The next line contains T integers, each representing a task's load.
Output Format:
- A single line containing S integers: the final loads of servers 0, 1, ..., S-1.
Example:
Input:
2 3
10 20 5
Output:
15 20
(Explanation: Task 10 -> Server 0 (Load 10). Task 20 -> Server 1 (Load 20). Task 5 -> Server 0 (Load 15).)
Key concepts
heapsimulation
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