Process Tasks Using Servers

Given server weights and task durations arriving one per second, assign each task to the available server with the smallest weight, breaking ties by server index. Return the assigned server index for each task.

Input Format

servers = server weights, tasks = task durations

Output Format

server index chosen for each task in arrival order

Constraints

  • 1 <= servers.length, tasks.length <= 10^5
  • 1 <= servers[i], tasks[i] <= 10^9

Examples

Example 1:

Input:

servers = [3,3,2]
tasks = [1,2,3,2,1,2]

Output:

[2,2,0,2,1,2]

Explanation:

This is the standard example: the lightest server is chosen whenever available.

Example 2:

Input:

servers = [5,1,4,3,2]
tasks = [2,1,2,4,5,2,1]

Output:

[1,4,1,4,1,3,2]

Explanation:

Servers are chosen by weight first, then by index.

Loading...
Process Tasks Using Servers - Heap DSA Problem