Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the last node in the doubly linked list.
DSA Go
current := head for current.[1] != nil { current = current.next }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' causes backward traversal.
Using 'head' or 'tail' as a pointer is incorrect here.
✗ Incorrect
To reach the last node, we follow the 'next' pointers until nil.
2fill in blank
mediumComplete the code to update the previous node's next pointer when deleting the last node.
DSA Go
if current.prev != nil { current.prev.[1] = nil }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prev pointer instead of next pointer.
Setting head or tail incorrectly.
✗ Incorrect
We set the previous node's 'next' pointer to nil to remove the last node.
3fill in blank
hardFix the error in updating the head pointer when the list has only one node.
DSA Go
if current.prev == nil { [1] = nil }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting current or tail to nil instead of head.
Not updating head at all.
✗ Incorrect
If the only node is deleted, head should be set to nil to indicate an empty list.
4fill in blank
hardFill both blanks to correctly delete the last node and update pointers.
DSA Go
if current.prev != nil { current.prev.[1] = nil } else { [2] = nil }
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing next and prev pointers.
Setting tail instead of head when list is empty.
✗ Incorrect
Set previous node's next to nil and if no previous node, set head to nil.
5fill in blank
hardFill all three blanks to complete the function that deletes the last node from a doubly linked list.
DSA Go
func deleteEnd(head *Node) *Node {
if head == nil {
return nil
}
current := head
for current.[1] != nil {
current = current.next
}
if current.prev != nil {
current.prev.[2] = nil
} else {
[3] = nil
}
return head
}Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next for traversal.
Setting wrong pointers when deleting the last node.
✗ Incorrect
Traverse using next, set prev node's next to nil, and if no prev node, set head to nil.
