Exponential Backoff Delays
Updated
Problem statement
Return the delay before each of attempts retries. The first delay is baseDelay; each later delay is multiplied by multiplier and capped at maxDelay.
Return an empty array for zero attempts.
Function
exponentialBackoff(baseDelay: int, multiplier: int, maxDelay: int, attempts: int) → int[]Examples
Example 1
baseDelay = 2multiplier = 3maxDelay = 20attempts = 5return = [2,6,18,20,20]The growth is capped after the third multiplication.
Example 2
baseDelay = 5multiplier = 2maxDelay = 100attempts = 0return = []No retry means no delay.
Constraints
1 <= baseDelay <= maxDelay <= 10^9.1 <= multiplier <= 1000.0 <= attempts <= 100000.
Source note: Author-written prompt excerpt retained for source fidelity.
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
- Mini-Batch Data LoaderOpenAI · PHONE SCREENOpenAI interview questions
- Shuffle a Deck From Random ChoicesGoogle · PHONE SCREENGoogle interview questions
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Deterministic K-Means AssignmentsLyft · PHONE SCREENLyft interview questions
- Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions