Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize a dummy node pointing to head.
DSA Go
dummy := &ListNode{Val: 0, Next: [1]Attempts:
3 left
💡 Hint
Common Mistakes
Setting dummy.Next to nil loses the list.
Pointing dummy.Next to dummy causes infinite loops.
✗ Incorrect
The dummy node's Next should point 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 Go
for i := 0; i < n; i++ { fast = [1] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using fast without .Next does not move the pointer.
Using fast.Prev moves backward, which is incorrect.
✗ Incorrect
To move fast pointer one step forward, assign fast = fast.Next inside the loop.
3fill in blank
hardFix the error in the loop condition to move both pointers until fast reaches the end.
DSA Go
for fast != [1] { fast = fast.Next slow = slow.Next }
Attempts:
3 left
💡 Hint
Common Mistakes
Using dummy or head in the condition causes infinite loops or wrong behavior.
Using slow in the condition is incorrect.
✗ Incorrect
The loop should continue until fast reaches nil, which means the end of the list.
4fill in blank
hardFill both blanks to remove the nth node from the end by adjusting pointers.
DSA Go
slow.Next = slow.[1].[2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using Prev is incorrect because the list is singly linked.
Using Prev.Prev or Next.Prev causes errors.
✗ Incorrect
To remove the node, link slow.Next to slow.Next.Next, skipping the target node.
5fill in blank
hardFill both blanks to return the new head of the list after removal.
DSA Go
return [1].[2]
Attempts:
3 left
💡 Hint
Common Mistakes
Returning head may return a removed node.
Returning dummy.Prev or dummy itself is incorrect.
✗ Incorrect
Return dummy.Next as the new head after removal, since dummy points before the original head.
