Retry schedule with exponential backoff

A free easy coding practice problem from devops. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.

Difficulty
Easy
Type
Function
Topic
Devops
Languages
JavaScript, TypeScript or Python

Problem

A payment webhook is retried with capped exponential backoff. The delay before retry i (0-based) is min(cap, base × factor^i) milliseconds. Keep scheduling retries while fewer than maxRetries have been scheduled AND adding the next delay keeps the total waiting time ≤ budget; stop at the first delay that would exceed the budget. Return the list of scheduled delays. 1 ≤ base ≤ cap ≤ 1,000,000, 1 ≤ factor ≤ 10, 0 ≤ maxRetries ≤ 60, 0 ≤ budget ≤ 1,000,000,000.

Function signature

// JavaScript
function retrySchedule(base, factor, cap, maxRetries, budget)

// TypeScript
function retrySchedule(base: any, factor: any, cap: any, maxRetries: any, budget: any): any

// Python
def retry_schedule(base, factor, cap, maxRetries, budget):

Examples

  1. retrySchedule(100, 2, 1000, 6, 100000) → [100,200,400,800,1000,1000]
  2. retrySchedule(500, 3, 10000, 10, 6000) → [500,1500]
  3. retrySchedule(250, 1, 250, 3, 1000) → [250,250,250]

How checking works

Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.

More practice problems

Next steps