Bring Servers Down
Updated
Problem statement
The developers at Amazon want to perform a reliability drill on some servers. There are n servers where the ith server can serve request[i] number of requests and has an initial health of health[i] units.
Each second, the developers send the maximum possible number of requests that can be served by all the available servers. With the request, the developers can also send a virus to one of the servers that can decrease the health of a particular server by k units. The developers can choose the server where the virus should be sent. A server goes down when its health is less than or equal to 0.
After all the servers are down, the developers must send one more request to conclude the failure of the application.
Find the minimum total number of requests that the developers must use to bring all the servers down.
Function
minimumRequests(request: int[], health: int[], k: int) → int
Complete the function minimumRequests in the editor.
minimumRequests has the following parameters:
- 1.
int[] request: an array of integers representing the number of requests each server can serve - 2.
int[] health: an array of integers representing the initial health of each server - 3.
int k: an integer representing the health decrease caused by the virus
Returns
int: the minimum total number of requests to bring all the servers down
Examples
Example 1
request = [3, 4]health = [4, 6]k = 3return = 21
Each server needs 2 virus hits: ceil(4 / 3) = 2 for the first server and ceil(6 / 3) = 2 for the second. Send the virus to the second server first. In seconds 1 and 2 both servers are up, so 3 + 4 = 7 requests are sent each second. After second 2 the second server is down. In seconds 3 and 4 only the first server is up, so 3 requests are sent each second. After all servers are down, one more request is sent. The total is 7 + 7 + 3 + 3 + 1 = 21, so the minimum number of requests required is 21.
Constraints
n == request.length == health.length1 <= n <= 5001 <= request[i] <= 100for each serveri1 <= health[i] <= 100for each serveri1 <= k <= 100
More Amazon interview questions
- Add Course Batches All or NothingONSITE INTERVIEW · Seen Dec 2026
- Priority Ad Rotation with Show LimitsONSITE INTERVIEW · Seen Dec 2026
- Next Greater Element IONSITE INTERVIEW · Seen Dec 2026
- Count Connected ComponentsPHONE SCREEN · Seen Dec 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Merge Accounts by Shared AttributePHONE SCREEN · Seen Dec 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Minimum Grid InconvenienceOA · Seen Dec 2026
- Optimal Account BalancingONSITE INTERVIEW · Seen Dec 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
Similar questions at other companies
- Maximum Bananas Delivered by a CamelStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- UCB1 Multi-Armed Bandit TraceWayfair · ONSITE INTERVIEWWayfair interview questions
- API Shield with Two Rolling LimitsGraviton · OA
- Expected Profit of a Doubling Betting SystemOptiver · OAOptiver interview questions
- Delete and Freeze GameRubrik · OARubrik interview questions
- Lock CodeVisa · OAVisa interview questions
- Bootstrap Decision Tree ClassifierPinterest · OAPinterest interview questions
- Predict Taxi Driver ClassesBoston Consulting Group · OABoston Consulting Group interview questions
- Arithmetic Triplets After QueriesCapital One · OACapital One interview questions
- IPO Share AllocationTwo Sigma · OATwo Sigma interview questions