Medium data structure and algorithm practice puzzle.
Given pending cylinder requests, where the head is now and the highest cylinder, return the total distance the head travels under SCAN: serve everything above in order, continue to the end, then reverse and serve everything below. Serving requests in arrival order instead makes the head cross the platter repeatedly, and seek time dominates everything else a spinning disk does. It is called the elevator algorithm for the obvious reason, and it goes to the end even with nothing left up there.
Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free.
Browse all 536 puzzles