Company: Amazon sde1 Off campus
Difficulty: medium
In Amazon's web infrastructure, the system logs n API requests per second, recording each request's response time in the array responseTimes , where each element denotes the time taken to respond to a single request. To prevent system overload, a throttling mechanism is applied with the following behaviour: In each step, select the request with the minimum response time. This request is prioritised for further analysis. Remove the selected request and its immediate neighbours in the array (based on original indices) from the logs permanently. This process continues until all requests are removed. The task is to calculate the total cumulative response time of all selected minimum requests over the entire throttling process. Note: If multiple requests have the same minimum response time, select the one with the lowest index. Example n = 4 responseTimes = [4, 2, 9, 1, 7, 3] Simulating the throttling mechanism: We maintain an active[] array to track which elements are still in the log. Ini