Request Redirection
The hackers of Hackerland want to deploy their applications on n servers. The ith server has requests[i] requests to serve but can serve a maximum of max_req[i] requests only.
In order to balance the load, the hackers need to redirect some requests of ith server to some other server. For each request that is redirecting the request from ith server to jth server, the latency is |i-j| where |i-j| represents the absolute value of i-j. The max_latency is defined as the maximum latency induced among all the redirections.
Given the number of servers n, requests array, find the minimum possible max_latency if the requests are redirected properly. Note that each server has to serve less than the maximum requests it can serve. If there is no way to serve all the requests, report -1 as the answer.
Complete the function getMinLatency in the editor.
getMinLatency has the following parameters:
requests[n]: An array of integersmax_req[n]: An array of integers
Returns
int: The minimal max_latency possible respecting the given conditions.
🌼 All credit goes to the amazing friend who helped out!
1Example 1
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 10^5