Retry with an Attempt Limit
Problem statement
Simulate a callable whose ordered outcomes are provided in outcomes. Each entry is either FAILURE or SUCCESS:value.
Invoke outcomes from left to right, using at most maxAttempts total attempts. Stop at the first success and return SUCCESS:value|attempts. If every permitted attempt fails, return FAILED|attempts.
Function
retry(outcomes: String[], maxAttempts: int) → StringExamples
Example 1
outcomes = ["FAILURE","FAILURE","SUCCESS:ready"]maxAttempts = 3return = "SUCCESS:ready|3"The third permitted attempt succeeds, so no later outcome is inspected.
Example 2
outcomes = ["FAILURE","SUCCESS:late"]maxAttempts = 1return = "FAILED|1"The attempt budget is exhausted before the success.
Constraints
1 <= outcomes.length <= 100000.1 <= maxAttempts <= outcomes.length.- Every entry is exactly
FAILUREor starts withSUCCESS:. - A success value contains printable ASCII characters and may be empty.