Skip to content
DeepForgeby svx
All problems
HardTime Seriests-179

Queue Length Forecast Lite

Problem

Forecast a deterministic fluid queue: each period the queue becomes max(0, queue + arrival_rate - service_rate). Return the queue length after each of the given periods, starting from initial_queue.

A negative queue is clipped to 0.

Hint

When service exceeds arrivals the queue drains, but never below zero.

Test cases

case 1
in: [3,2,0,4]
expected: [1,2,3,4]
case 2
in: [1,3,5,4]
expected: [3,1,0,0]
case 3
in: [2,2,10,2]
expected: [10,10]
case 4
in: [0,1,0,3]
expected: [0,0,0]
Starter codePython
def queue_length_forecast_lite(arrival_rate, service_rate, initial_queue, periods):
    # Your code here
    pass

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