Drill

ProblemsC# › network

Exponential backoff with a ceiling

easynetworkMathBit manipulationC#

Retries should space out exponentially — double the delay each attempt — but never exceed a sixty-second cap.

BackoffFixed(attempt: int, baseMs: int) → int

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public int BackoffFixed(int attempt, int baseMs) {
    
}

Worked examples

CallResult
BackoffFixed(0, 100)100
BackoffFixed(1, 100)200
BackoffFixed(2, 100)400
BackoffFixed(3, 100)800

Hint

Start at baseMs and double in a loop; clamp on each step.

Reference solution in C#
public int BackoffFixed(int attempt, int baseMs) {
    if (attempt <= 0) return Math.Min(baseMs, 60000);
    int value = baseMs;
    for (int i = 0; i < attempt; i++) {
        value = value * 2;
        if (value > 60000) value = 60000;
    }
    return value;
}

The same problem in another language

More network problems in C#