Complete the code to create a dummy node pointing to the head.
const dummy = new ListNode(0, [1]);
The dummy node should point to the head of the list to simplify edge cases.
Complete the code to move the first pointer n steps ahead.
for (let i = 0; i < n; i++) { first = first[1]; }
To move forward in a singly linked list, use the .next pointer.
Fix the error in the while loop condition to move both pointers until first reaches the end.
while (first[1] !== null) { first = first.next; second = second.next; }
The loop should continue while first.next is not null to avoid overshooting the list.
Fill both blanks to remove the nth node from the end by skipping it.
second[1] = second[2].next;
We set second.next to second.next.next to skip the node to remove.
Fill all three blanks to return the new head of the list after removal.
return dummy[1];
After removal, the new head is dummy.next.
