Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-214

Lindley Waiting Time Sequence

Problem

Simulate the Lindley recursion over a sequence of service times and interarrival times, starting from an empty queue:

W_next = max(0, W + service - interarrival).

Return the average waiting time over the jobs. Return 0.0 for an empty sequence.

Hint

Accumulate each job's wait before updating it with the recursion.

Test cases

case 1
in: [[2,3],[4,1]]
expected: 0
case 2
in: [[3,2],[1,2]]
expected: 1
case 3
in: [[1,1,1],[1,1,1]]
expected: 0
case 4
in: [[],[]]
expected: 0
Starter codePython
def lindley_waiting_times(services, interarrivals):
    # Your code here
    pass

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