Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-200

Shortest-Job-First Expected Wait

Problem

For jobs of the given sizes all available at time 0, shortest-job-first minimizes the mean waiting time. Sort the sizes ascending, form the prefix sums (the first job waits 0), and return their mean.

Return 0.0 for an empty list.

Hint

Sorting ascending is what makes the prefix sums smallest overall.

Test cases

case 1
in: [[1,2,3]]
expected: 1.3333333333333333
case 2
in: [[3,1,2]]
expected: 1.3333333333333333
case 3
in: [[5]]
expected: 0
case 4
in: [[]]
expected: 0
Starter codePython
def sjf_expected_wait(job_sizes):
    # Your code here
    pass

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