Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize a dummy node pointing to the head.
DSA Javascript
const dummy = new ListNode(0); dummy.next = [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dummy.next to null breaks the list.
Using dummy instead of head causes infinite loops.
✗ Incorrect
We create a dummy node and set its next pointer to the head of the list to simplify edge cases.
2fill in blank
mediumComplete the code to move the fast pointer n steps ahead.
DSA Javascript
for (let i = 0; i < n; i++) { fast = fast[1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next moves backward or causes errors.
Using ++ on a pointer is invalid.
✗ Incorrect
To move forward in a linked list, we use the .next pointer.
3fill in blank
hardFix the error in the while loop condition to move both pointers until fast reaches the end.
DSA Javascript
while (fast[1] !== null) { fast = fast.next; slow = slow.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' without dot causes syntax errors.
Using arrow or bracket notation is invalid in JavaScript.
✗ Incorrect
In JavaScript, to access a property, use dot notation without quotes: .next
4fill in blank
hardFill both blanks to remove the nth node from the end by skipping it.
DSA Javascript
slow[1] = slow[2].next;
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next causes errors.
Not skipping the node properly leaves the list unchanged.
✗ Incorrect
We set slow.next to slow.next.next to skip the node to be removed.
5fill in blank
hardComplete the code to return the new head of the list after removal.
DSA Javascript
return dummy[1];
Attempts:
3 left
💡 Hint
Common Mistakes
Returning head may be incorrect if the first node was removed.
Using .prev or .next.next on dummy is invalid.
✗ Incorrect
After removal, the new head is dummy.next, which may differ if the first node was removed.
