FastPrepExponential Backoff Delays

Exponential Backoff Delays

Wonderful logoWonderful● EasyFULLTIMEPHONE SCREEN
Learn

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.

See Wonderful hiring insights
public int[] exponentialBackoff(int baseDelay, int multiplier, int maxDelay, int attempts) {
    // Write your code here.
}
baseDelay2
multiplier3
maxDelay20
attempts5
expected[2,6,18,20,20]
Checking account…