Take down servers in a reliability drill with minimum total requests
A reliability drill shuts down a fleet of n servers. Server i handles request[i] requests every second while it is up, and starts with health[i] health. You are also given an integer k.
The drill runs in whole seconds. In each second:
- Every server that is still up receives its full load, so the drill sends
request[i]requests to each live serveri. - You inject one virus into a single live server of your choice, lowering its health by
k. A server whose health reaches 0 or below goes down and receives no more requests.
After the last server goes down, the drill sends one extra request to confirm the outage.
Implement min_total_requests(request: list[int], health: list[int], k: int) -> int that returns the minimum total number of requests sent over the whole drill, including the confirmation request.
Constraints
0 <= n <= 10^51 <= request[i], health[i] <= 10^91 <= k <= 10^9
Example 1
request = [1, 5, 2], health = [3, 2, 4], k = 2
output: 17
Server 1 needs one hit, servers 0 and 2 need two each. Take down server 1 (second 1), then server 2 (seconds 2-3), then server 0 (seconds 4-5). Requests: second 1 sends 1+5+2 = 8, seconds 2-3 send 1+2 = 3 each, seconds 4-5 send 1 each. Total 8 + 6 + 2 = 16, plus the confirmation request = 17.
Example 2
request = [7], health = [10], k = 3
output: 29
The server needs 4 hits, so it receives 7 requests in each of 4 seconds (28), plus 1 confirmation.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
