Skip to content
DeepForgeby svx
All problems
MediumAlgorithmsal-246

SCAN Disk Scheduling

Problem

Given the current head position, pending requests and a direction, return the order in which SCAN (elevator) scheduling services the requests.

When the direction is up, serve all requests at or above the head in increasing order, then the lower requests in decreasing order; down is the mirror image. Requests exactly at the head are served first when moving up.

Hint

The head sweeps to the end in one direction before reversing to serve the other side.

Test cases

case 1
in: [53,[98,183,37,122,14,124,65,67],"up"]
expected: [65,67,98,122,124,183,37,14]
case 2
in: [53,[98,183,37,122,14,124,65,67],"down"]
expected: [37,14,65,67,98,122,124,183]
case 3
in: [0,[1],"up"]
expected: [1]
case 4
in: [10,[],"up"]
expected: []
case 5
in: [10,[5,15,7,12],"down"]
expected: [7,5,12,15]
Starter codePython
def scan_disk_order(head, requests, direction):
    # Your code here
    pass

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