Retry Backoff Schedule
Retry Backoff Schedule
You are simulating a retry policy with exponential backoff. An initial attempt happens at start time. After each failure, the next attempt is scheduled after a delay:
delay = min(maxDelay, baseDelay * 2^(failuresSoFar))
Where failuresSoFar starts at 0 for the first failure.
Given the outcomes of attempts in order, return the scheduled times of the attempts that actually occur. Stop when an attempt succeeds.
Function signature
func RetrySchedule(start int, outcomes []bool, baseDelay int, maxDelay int) []int
Example
start=0, baseDelay=5, maxDelay=20
outcomes = [false, false, true]
attempt times:
- t=0 (fail)
- t=5 (fail) delay=5
- t=15 (success) delay=10
output = [0,5,15]
Constraints
0 <= len(outcomes) <= 1000000 <= start, baseDelay, maxDelay <= 1_000_000
Notes
- If
outcomesis empty, return an empty slice. - If
baseDelayis 0, all retries happen at the same time as the previous attempt.
Run tests to see results
No issues detected