Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-195

Discrete-Event Step

Problem

Apply one event to a queue state. event_type 1 is an arrival (queue length plus 1), event_type 0 is a departure (queue length minus 1, never below 0), and any other event type changes nothing. Return the new queue length.

Hint

Departures from an empty queue are lost.

Test cases

case 1
in: [0,1]
expected: 1
case 2
in: [0,0]
expected: 0
case 3
in: [3,0]
expected: 2
case 4
in: [3,5]
expected: 3
Starter codePython
def discrete_event_step(queue_length, event_type):
    # Your code here
    pass

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