FastPrepRetry with an Attempt Limit

Retry with an Attempt Limit

Oracle logoOracleEasyFULLTIMEONSITE INTERVIEW
Learn

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) → String

Examples

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 FAILURE or starts with SUCCESS:.
  • A success value contains printable ASCII characters and may be empty.

More Oracle problems

See Oracle hiring insights
public String retry(String[] outcomes, int maxAttempts) {
    // Write your code here.
}
outcomes["FAILURE","FAILURE","SUCCESS:ready"]
maxAttempts3
expected"SUCCESS:ready|3"
Checking account…