Process Refunds with Bounded Retries
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
SandF. - Requests are independent.