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 <= 60