Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find Servers That Handled Most Number of Requests

XPChallenge Points: 30
levelLevel: Hard

You are managing k servers, numbered from 0 to k−1, where each server can process only one request at a time, but can process unlimited requests over time.
You receive a list of incoming requests, where:

  • arrival[i] → time when the i-th request comes

  • load[i] → duration needed to complete that request

A request must be assigned using this rule:

  1. Start checking from server i % k.

  2. If that server is free at arrival time, assign the request to it.

  3. Otherwise, move forward one server at a time (circular manner) until a free server is found.

  4. If no server is free, the request is ignored.

Your goal is to determine which servers handled the most total requests.
Return their indices in any order.

Example 1:

Input: k = 2 arrival = [1,5,5,6] load = [4,2,3,2]

Output: [0]

Explanation:

Server 0 handles request 0. Request 1 goes to server 1. Request 2 arrives but both are busy → dropped. Request 3 goes to server 0. Server 0 handled 2 requests, more than server 1.

Example 2:

Input: k = 4 arrival = [2,4,6,8,10] load = [3,3,3,3,3]

Output: [0,1,2,3]

Explanation:

Every request arrives exactly when the previous one finishes. All servers process exactly one request each. Therefore, all servers are equally busy.

Example 3:

Input: k = 5 arrival = [1,2,10,12,13] load = [5,3,1,1,1]

Output: [2,3,4]

Explanation:

- Requests 2,3,4 go to servers 2,3,4 respectively. - They each handle one request. - No other server processes any request.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result