Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move the fast pointer n steps ahead.
DSA Java
for (int i = 0; i < [1]; i++) { fast = fast.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length of the list instead of n.
Using an undefined variable like count or index.
✗ Incorrect
We need to move the fast pointer n steps ahead to create a gap of n nodes between fast and slow pointers.
2fill in blank
mediumComplete the code to advance both pointers until fast reaches the end.
DSA Java
while (fast.next != null) { slow = slow.[1]; fast = fast.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is not defined in singly linked list.
Using incorrect pointer names like 'child' or 'forward'.
✗ Incorrect
To move the slow pointer forward, we use slow.next to go to the next node.
3fill in blank
hardFix the error in removing the nth node by updating the pointer correctly.
DSA Java
slow.next = slow.[1].next;Attempts:
3 left
💡 Hint
Common Mistakes
Using slow.prev which does not exist in singly linked list.
Using incorrect pointer names causing runtime errors.
✗ Incorrect
To remove the nth node, we skip it by pointing slow.next to slow.next.next.
4fill in blank
hardFill both blanks to initialize dummy node and set slow pointer.
DSA Java
ListNode dummy = new ListNode([1]); dummy.next = head; ListNode slow = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing dummy with head or null instead of 0.
Setting slow pointer to head instead of dummy.
✗ Incorrect
Dummy node is initialized with 0 value and slow pointer starts at dummy to handle edge cases.
5fill in blank
hardFill both blanks to return the correct head after removal.
DSA Java
return [1].[2];
Attempts:
3 left
💡 Hint
Common Mistakes
Returning head directly which may be removed node.
Using dummy.prev which does not exist.
✗ Incorrect
After removal, the new head is dummy.next because dummy points before the original head.
