A mobile app at Nimbus Mobile fetches data from several endpoints. Each request may time out multiple times before succeeding, and the app retries with exponential backoff.
Implement a function that computes when each request finally succeeds, assuming requests are processed independently and each retry waits longer than the previous one.
Given:
timeouts: an array where timeouts[i] is the number of consecutive timeouts before request i succeeds.base_delay: the delay after the first timeout.max_retries: the maximum number of retries allowed.For each request:
0.base_delay, 2 * base_delay, 4 * base_delay, ...max_retries, return the total elapsed wait time before success.max_retries, return -1 for that request.Return an array of results for all requests.
Example 1
timeouts = [0, 1, 2], base_delay = 3, max_retries = 3[0, 3, 9]3. The third waits 3 + 6 = 9.Example 2
timeouts = [4, 2], base_delay = 2, max_retries = 3[-1, 6]2 + 4 = 6 before succeeding.1 <= len(timeouts) <= 10^50 <= timeouts[i] <= 10^91 <= base_delay <= 10^60 <= max_retries <= 60timeouts = [0, 1, 2], base_delay = 3, max_retries = 3Output[0, 3, 9]WhyRequest 0 succeeds immediately. Request 1 waits 3. Request 2 waits 3 + 6 = 9.timeouts = [4, 2], base_delay = 2, max_retries = 3Output[-1, 6]WhyA request needing 4 timeouts exceeds the retry limit of 3, so it fails. The other request waits 2 + 4 = 6.timeouts = [3, 0, 1], base_delay = 1, max_retries = 3Output[7, 0, 1]WhyThe cumulative waits are 1, 1+2=3, and 1+2+4=7. So the results are 7, 0, and 1.1 <= len(timeouts) <= 10^50 <= timeouts[i] <= 10^91 <= base_delay <= 10^60 <= max_retries <= 60def schedule_retries(timeouts, base_delay, max_retries):