Skip to content
DeepForgeby svx
All problems
HardDeep Learningdl-316

Continuous Batching Slot Simulation

Problem

Simulate a continuous batching scheduler. One request arrives per step starting at step 0; at each step, as many waiting requests as possible start (up to max_slots), then every active request advances one step of service_steps. Repeat until all requests finish. Return the number of steps taken.

The signature is continuous_batching_slots(num_requests, service_steps, max_slots).

Hint

Continuous batching admits new requests the moment a slot frees, unlike static batching.

Test cases

case 1
in: [4,2,2]
expected: 4
case 2
in: [3,1,2]
expected: 2
case 3
in: [1,5,4]
expected: 5
case 4
in: [6,2,3]
expected: 4
Starter codePython
def continuous_batching_slots(num_requests, service_steps, max_slots):
    # Your code here
    pass

4 test cases · run your code against them in the editor