FastPrepProcess Refunds with Bounded Retries

Process Refunds with Bounded Retries

Mercor logoMercor● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Process independent refund requests. alreadyDone[i] tells whether request i was completed before this batch. attemptPatterns[i] lists the outcomes returned by successive payment attempts: S is success and F is failure.

If a request is already done, make zero attempts and return DONE:0. Otherwise make at most three attempts and stop on the first success. Return DONE:k after a success on attempt k. If every available attempt among the first three fails, return PENDING:k, where k is the number attempted.

Function

processRefundRetries(alreadyDone: boolean[], attemptPatterns: String[]) → String[]

Examples

Example 1

alreadyDone = [false,false,true]attemptPatterns = ["FFS","FFFF","S"]return = ["DONE:3","PENDING:3","DONE:0"]

A refund becomes done only after success, and an existing completion performs no attempt.

Example 2

alreadyDone = [false,false]attemptPatterns = ["S","FS"]return = ["DONE:1","DONE:2"]

The first success stops retries.

Example 3

alreadyDone = []attemptPatterns = []return = []

An empty batch has no results.

Constraints

  • 0 <= alreadyDone.length == attemptPatterns.length <= 100000.
  • Every pattern has length from 0 through 100 and contains only S and F.
  • Requests are independent.

More Mercor problems

See Mercor hiring insights
public String[] processRefundRetries(boolean[] alreadyDone, String[] attemptPatterns) {
    // Write your solution here.
}
alreadyDone[false,false,true]
attemptPatterns["FFS","FFFF","S"]
expected["DONE:3", "PENDING:3", "DONE:0"]
Checking account…