1. Description
There are k servers numbered 0 through k - 1, each handling at most one request at a time.
Request i arrives at arrival[i] and takes load[i] time units. The arrival times are strictly increasing.
Assign each request to the first available server starting from i % k, checking increasing server IDs and wrapping around to 0. Drop the request if all servers are busy.
A server finishing at time t can accept a request arriving at t.
Return the IDs of all servers that handle the most requests, in any order.
2. Example
Example 1
Input: k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3]
Output: [1]
Explanation: Server 1 handles two requests; servers 0 and 2 handle one each. The last request is dropped.
Example 2
Input: k = 3, arrival = [1,2,3,4], load = [1,2,1,2]
Output: [0]
Explanation: Server 0 handles two requests, while each other server handles one.
Example 3
Input: k = 3, arrival = [1,2,3], load = [10,12,11]
Output: [0,1,2]
Explanation: Each server handles one request.
3. Constraints
- 1 <= k <= 10$^5$
- 1 <= arrival.length, load.length <= 10$^5$
- arrival.length == load.length
- 1 <= arrival[i], load[i] <= 10$^9$
- arrival is strictly increasing.
4. Solutions
Ordered Set && Min-Heap
n = arrival.size(), k = number of servers
Time complexity: O((n + k) log k)
Space complexity: O(k)
| |