Servers That Handled the Most Requests
A fleet of k servers handles incoming requests. Request i prefers server (i mod k); if busy it scans forward (wrapping) to the next free server, else it is dropped. Report which servers handled the most requests.
Problem
Given k servers (0..k-1), arrays arrival and load (request i arrives at arrival[i] and occupies a server for load[i] time), each request goes to the first free server at or after index (i mod k), wrapping around; if all are busy it is dropped. Return the indices of the server(s) that handled the maximum number of requests.
Input
An integer k, a strictly increasing array arrival, and an array load of equal length.
Output
A list of server indices (any order) that handled the most requests.
Constraints
- 1 <= k <= 100000
- 1 <= arrival.length, load.length <= 100000
- arrival is strictly increasing; 1 <= load[i] <= 10^9.
Examples
Example 1
Input
k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3]
Output
[1]
Server 1 ends up handling the most requests.
Example 2
Input
k = 3, arrival = [1,2,3,4], load = [1,2,1,2]
Output
[0]
Server 0 frees up in time to take extra requests.