FastPrepAPI Bandwidth Allocation

API Bandwidth Allocation

Arista Networks logoArista Networks● MediumNEW GRADOA
Learn

Problem statement

Each API endpoint consumes bandwidth[i] units when enabled and resolves requests[i] requests. An endpoint is either enabled once or not enabled.

Given the total available maxBandwidth, return the maximum number of requests that can be resolved without exceeding the bandwidth limit.

Function

maximizeResolvedRequests(maxBandwidth: int, bandwidth: int[], requests: int[]) → int

Examples

Example 1

maxBandwidth = 5bandwidth = [2,3,4]requests = [4,5,7]return = 9

Case 1 exercises the documented deterministic contract.

Example 2

maxBandwidth = 7bandwidth = [2,3,4]requests = [4,5,7]return = 12

Case 2 exercises the documented deterministic contract.

Example 3

maxBandwidth = 0bandwidth = [1,2]requests = [10,20]return = 0

Case 3 exercises the documented deterministic contract.

Constraints

  • 0 <= maxBandwidth <= 10000.
  • 1 <= bandwidth.length == requests.length <= 200.
  • 1 <= bandwidth[i] <= 10000.
  • 0 <= requests[i] <= 10^6.
  • The optimal answer fits a signed 32-bit integer.

More Arista Networks problems

See Arista Networks hiring insights
public int maximizeResolvedRequests(int maxBandwidth, int[] bandwidth, int[] requests) {
    // Write your code here.
}
maxBandwidth5
bandwidth[2,3,4]
requests[4,5,7]
expected9
Checking account…