Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to swap the next and prev pointers of the current node.
DSA Go
current.[1], current.prev = current.prev, current.nextAttempts:
3 left
💡 Hint
Common Mistakes
Swapping with the wrong fields like value or head.
Not swapping both pointers at once.
✗ Incorrect
Swapping current.next and current.prev reverses the direction of the links for the current node.
2fill in blank
mediumComplete the code to move to the next node after swapping pointers.
DSA Go
current = current.[1]Attempts:
3 left
💡 Hint
Common Mistakes
Using current.next instead of current.prev after swapping.
Using unrelated fields like head or tail.
✗ Incorrect
After swapping, current.prev points to the next node in the original list, so we move to current.prev.
3fill in blank
hardFix the error in updating the head pointer after reversing the list.
DSA Go
if temp != nil { head = temp.[1] }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to temp.next which is nil or incorrect.
Using value or tail fields incorrectly.
✗ Incorrect
After the loop, temp.prev points to the new head, so update head to temp.prev.
4fill in blank
hardFill both blanks to correctly initialize and traverse the doubly linked list for reversal.
DSA Go
temp := [1] for current != nil { current.[2], current.prev = current.prev, current.next current = current.prev }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from nil or wrong node.
Swapping wrong pointers.
✗ Incorrect
We start from head and swap current.next with current.prev to reverse links.
5fill in blank
hardFill all three blanks to complete the function that reverses a doubly linked list and returns the new head.
DSA Go
func reverseDoublyLinkedList(head *Node) *Node {
var current = head
var temp *Node = [1]
for current != nil {
temp = current.[2]
current.[3], current.prev = current.prev, current.next
current = current.prev
}
if temp != nil {
head = temp.prev
}
return head
}Attempts:
3 left
💡 Hint
Common Mistakes
Initializing temp incorrectly.
Swapping or updating pointers in wrong order.
✗ Incorrect
Initialize temp as nil, update temp to current.prev before swapping, then swap current.next and current.prev.
