Batch API Requests with Retry Delays
Problem statement
You are given request IDs, the number of failed attempts each request will produce before succeeding, and a fixed retry delay for each request. All requests are initially eligible at logical time 0.
Repeatedly dispatch a batch containing the first at most five eligible unfinished requests in original input order. A failed attempt reduces that request's remaining failure count and makes it eligible again at currentTime + retryDelay; a successful attempt completes it. If no request is eligible, jump to the smallest next eligibility time.
Return one line per batch as time:id1,id2,.... Multiple batches may occur at the same time when more than five requests are eligible.
Function
scheduleRequestBatches(requestIds: String[], failuresBeforeSuccess: int[], retryDelays: int[]) → String[]Examples
Example 1
requestIds = ["a","b"]failuresBeforeSuccess = [1,0]retryDelays = [5,1]return = ["0:a,b","5:a"]b succeeds immediately; a fails once and returns at time 5.
Example 2
requestIds = ["a","b","c","d","e","f"]failuresBeforeSuccess = [0,0,0,0,0,0]retryDelays = [1,1,1,1,1,1]return = ["0:a,b,c,d,e","0:f"]The six initially eligible requests require two batches at time 0.
Constraints
1 <= requestIds.length <= 10^4; all three arrays have the same length.- IDs are unique and contain no colon or comma.
- Failure counts are nonnegative; retry delays are positive.