Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move the fast pointer n steps ahead.
DSA C#
for (int i = 0; i < [1]; i++) { fast = fast.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using length or count instead of n.
Moving the pointer less or more than n steps.
✗ Incorrect
We need to move the fast pointer exactly n steps ahead to find the nth node from the end.
2fill in blank
mediumComplete the code to check if fast pointer reached the end after moving n steps.
DSA C#
if (fast == [1]) { return head.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if fast equals head or tail instead of null.
Returning head instead of head.next.
✗ Incorrect
If fast is null after moving n steps, it means we need to remove the first node.
3fill in blank
hardFix the error in the loop condition to move both pointers until fast reaches the end.
DSA C#
while (fast.[1] != null) { fast = fast.next; slow = slow.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using fast.prev or fast.value which are incorrect here.
Checking fast.head which does not exist.
✗ Incorrect
We check fast.next to see if fast can move forward; if not, we stop.
4fill in blank
hardFill both blanks to remove the nth node from the end by adjusting pointers.
DSA C#
slow.[1] = slow.[2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev pointers which do not exist in singly linked list.
Setting slow.next to slow.next.prev which is invalid.
✗ Incorrect
We set slow.next to skip the node to remove by pointing to slow.next.next.
5fill in blank
hardFill all three blanks to complete the RemoveNthFromEnd method.
DSA C#
public ListNode RemoveNthFromEnd(ListNode head, int n) {
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode fast = dummy;
ListNode slow = dummy;
for (int i = 0; i < [1]; i++) {
fast = fast.next;
}
while (fast.[2] != null) {
fast = fast.next;
slow = slow.next;
}
slow.[3] = slow.next.next;
return dummy.next;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next.
Incorrect loop conditions or pointer updates.
✗ Incorrect
Move fast n steps, then move both until fast.next is null, then skip the target node.
