Skip to interview prep
Apexed

4. Fix the retry policy

MediumDebugging & productionDebugging

callWithRetry(statuses, maxAttempts) simulates calling a flaky API: statuses[i] is the HTTP status returned by attempt i + 1. Return { status, attempts, delays }.

Rules: retry only on 429, 500, 502, 503 or 504; never exceed maxAttempts total attempts; wait 100 ms before the first retry and double the wait each time (capped at 1000 ms). delays lists the waits used. The current code hammers the API and retries client errors.

Example 1

Input: callWithRetry([503, 503, 200], 3)
Output: { status: 200, attempts: 3, delays: [100, 200] }

Constraints

  • Fix the bug; keep the function signature

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Fix the retry policy — coding interview practice — Apexed