Dynamic Batch Completion Times
Problem statement
All generation sequences are waiting at time 0 in input order. A dynamic batch has batchSize identical slots. A sequence of length L occupies one slot for L time units.
Whenever a slot becomes free, immediately assign the next waiting sequence. If several slots become free together, use the smaller slot index first. Return each sequence’s completion time in input order.
Function
dynamicBatchCompletionTimes(sequenceLengths: int[], batchSize: int) → int[]Examples
Example 1
sequenceLengths = [2,1,3]batchSize = 2return = [2,1,4]The length-1 sequence finishes first; the third sequence immediately takes that slot.
Example 2
sequenceLengths = [3,3,3]batchSize = 1return = [3,6,9]One slot processes every sequence serially.
Example 3
sequenceLengths = [1,1,1,1]batchSize = 2return = [1,1,2,2]Two sequences finish at each time step.
Constraints
1 <= sequenceLengths.length <= 100000.1 <= batchSize <= sequenceLengths.length.1 <= sequenceLengths[i] <= 100000.