Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move the fast pointer n steps ahead.
DSA Python
for _ in range([1]): fast = fast.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of n causes the gap to be incorrect.
Using 0 means the fast pointer doesn't move ahead at all.
✗ Incorrect
We need to move the fast pointer exactly n steps ahead to maintain the gap.
2fill in blank
mediumComplete the condition to move both pointers until fast reaches the end.
DSA Python
while fast.next [1] None: fast = fast.next slow = slow.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' None stops the loop too early.
Using '<' or '>' with None is invalid.
✗ Incorrect
We continue moving while fast.next is not None, meaning fast has not reached the last node.
3fill in blank
hardFix the error in removing the target node by correctly updating the next pointer.
DSA Python
slow.next = slow.next[1]next Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '->' causes syntax errors in Python.
Using '=>' or '::' are invalid in this context.
✗ Incorrect
In Python, the dot operator '.' is used to access attributes like 'next' of an object.
4fill in blank
hardFill both blanks to correctly handle the edge case when the head node is removed.
DSA Python
if fast is [1]: return [2].next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if fast is head is incorrect here.
Returning head instead of head.next does not remove the node.
✗ Incorrect
If fast is None after moving n steps, it means we remove the head node, so return head.next.
5fill in blank
hardFill all three blanks to complete the function that removes the nth node from the end.
DSA Python
def removeNthFromEnd(head, n): dummy = ListNode(0) dummy.next = head fast = dummy slow = dummy for _ in range([1]): fast = fast.next while fast.next [2] None: fast = fast.next slow = slow.next slow.next = slow.next[3]next return dummy.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators in the while loop.
Using wrong attribute access operator.
Not moving fast pointer n steps first.
✗ Incorrect
Move fast pointer n steps, loop while fast.next != None, then remove node by linking slow.next to slow.next.next.