Wait times for retries
Python data engineering interview problem. Difficulty: beginner. Pattern: Arrays. About 10 minutes. Free to practice.
Build the list of waiting times for a retry policy where each wait doubles up to a maximum. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
When a task fails, a pipeline waits before trying again, and the wait doubles after every failure up to a maximum. Implement retry_delays(attempts, base, cap). Return a list with one delay, in seconds, for each retry. The first delay is base, the second is 2 * base, the third is 4 * base, and so on. No delay is ever larger than cap. If attempts is 0, return an empty list.
Requirements
- Delays double each time.
- No delay is larger than cap.
Constraints
- attempts is between 0 and 30.
- base and cap are positive whole numbers.
Examples
Input: retry_delays(5, 3, 20) Output: [3, 6, 12, 20, 20] Once doubling would pass 20, the delay stays at 20.
Topics: lakebench, python, retry, backoff, pipeline.
More Python interview questions · All interview problems · Learn data engineering
Wait times for retries
Interview-style drill: Build the list of waiting times for a retry policy where each wait doubles up to a maximum.
When a task fails, a pipeline waits before trying again, and the wait doubles after every failure up to a maximum. Implement `retry_delays(attempts, base, cap)`. - Return a list with one delay, in seconds, for each retry. - The first delay is `base`, the second is `2 * base`, the third is `4 * base`, and so on. - No delay is ever larger than `cap`. - If `attempts` is 0, return an empty list.