Drill

ProblemsJava › payments

Should this call be retried

mediumpaymentsMathJava

The gateway client decides whether a failed call is worth trying again, or whether retrying would only make things worse.

shouldRetry(status: int, attempt: int) → bool

Java 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

boolean shouldRetry(int status, int attempt) {
    
}

Worked examples

CallResult
shouldRetry(500, 1)true
shouldRetry(429, 2)true
shouldRetry(503, 3)false
shouldRetry(404, 1)false

Hint

Deal with the attempt ceiling first, then the status.

Reference solution in Java
boolean shouldRetry(int status, int attempt) {
    if (attempt < 1 || attempt >= 3) return false;
    return status == 429 || (status >= 500 && status <= 599);
}

The same problem in another language

More payments problems in Java