Solution
Given
Request queue: 45, 81, 185, 33, 175, 99, 150, 77
Initial head position: 58
SSTF idea (quick recap)
At every step, move the head to the closest unserved request (minimum absolute distance from current head).
Work it out (carefully, one hop at a time)
Current head = 58; pending = {45, 81, 185, 33, 175, 99, 150, 77}
-
Nearest to 58 → 45 (|58−45| = 13)
Move: 58 → 45, distance = 13
Pending now {81, 185, 33, 175, 99, 150, 77}
-
Nearest to 45 → 33 (|45−33| = 12)
Move: 45 → 33, distance = 12
Pending {81, 185, 175, 99, 150, 77}
-
Nearest to 33 → 77 (|33−77| = 44)
Move: 33 → 77, distance = 44
Pending {81, 185, 175, 99, 150}
-
Nearest to 77 → 81 (|77−81| = 4)
Move: 77 → 81, distance = 4
Pending {185, 175, 99, 150}
-
Nearest to 81 → 99 (|81−99| = 18)
Move: 81 → 99, distance = 18
Pending {185, 175, 150}
-
Nearest to 99 → 150 (|99−150| = 51)
Move: 99 → 150, distance = 51
Pending {185, 175}
-
Nearest to 150 → 175 (|150−175| = 25)
Move: 150 → 175, distance = 25
Pending {185}
-
Last → 185 (|175−185| = 10)
Move: 175 → 185, distance = 10
Pending {}

Sequence serviced
58 → 45 → 33 → 77 → 81 → 99 → 150 → 175 → 185
Total head movement
Add the distances: 13 + 12 + 44 + 4 + 18 + 51 + 25 + 10 = 177 cylinders
✅ Answer: 177