Problem · Array

Server Management

Learn this problem
EasyRippling logoRipplingNEW GRADOA

Problem statement

A company has n servers. For server i, serverCapacity[i] is its capacity and incomingRequests[i] is the number of requests arriving at that server.

Without an upgrade, server i can handle at most min(serverCapacity[i], incomingRequests[i]) requests.

Choose exactly k servers and double their capacities. Return the maximum total number of requests that can be handled across all servers after these upgrades.

Function

maximumHandledRequests(serverCapacity: int[], incomingRequests: int[], k: int) → long

Examples

Example 1

serverCapacity = [10,4,3,7]incomingRequests = [3,10,4,5]k = 2return = 20

Double the capacities of servers 1 and 2, using zero-based indices. The four servers can then handle 3, 8, 4, and 5 requests, for a total of 20.

Constraints

  • 1 <= k <= serverCapacity.length <= 2 * 10^5
  • serverCapacity.length == incomingRequests.length
  • 1 <= serverCapacity[i], incomingRequests[i] <= 10^9

More Rippling problems

drafts saved locally
public long maximumHandledRequests(int[] serverCapacity, int[] incomingRequests, int k) {
    // Write your code here.
}
serverCapacity[10,4,3,7]
incomingRequests[3,10,4,5]
k2
expected20
checking account