Bird
0
0
LLDsystem_design~10 mins

Scheduling algorithm (SCAN, LOOK) in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the initial direction for the SCAN algorithm.

LLD
direction = [1]  # Choose initial head movement direction
Drag options to blanks, or click blank then click option'
A"down"
B"up"
C"right"
D"left"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a direction unrelated to disk tracks like 'up' or 'down'.
2fill in blank
medium

Complete the code to find the next request to service in the LOOK algorithm.

LLD
next_request = min([r for r in requests if r > current_head], default=[1])
Drag options to blanks, or click blank then click option'
A-1
BNone
C0
Dcurrent_head
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or -1 which may be valid track numbers and cause errors.
3fill in blank
hard

Fix the error in the code that updates the head position after servicing a request in SCAN.

LLD
current_head = [1]  # Update head to the serviced request
Drag options to blanks, or click blank then click option'
Anext_request
Brequests.pop()
Crequests[0]
Dcurrent_head + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using requests.pop() which removes but may not be the correct request.
Incrementing head by 1 regardless of request location.
4fill in blank
hard

Fill both blanks to complete the condition that reverses direction in SCAN when no requests remain in current direction.

LLD
if not any(r [1] current_head for r in requests):
    direction = [2]
Drag options to blanks, or click blank then click option'
A>
B<
C"left"
D"right"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or wrong direction strings.
5fill in blank
hard

Fill all three blanks to complete the LOOK algorithm's main loop for servicing requests.

LLD
while requests:
    if direction == [1]:
        next_request = min([r for r in requests if r > current_head], default=None)
    else:
        next_request = max([r for r in requests if r < current_head], default=None)
    if next_request is None:
        direction = [2] if direction == [1] else [1]
        continue
    current_head = [3]
    requests.remove(next_request)
Drag options to blanks, or click blank then click option'
A"right"
B"left"
Cnext_request
Dcurrent_head
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing direction strings, not updating head correctly, or reversing direction incorrectly.