Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the next node in the circular linked list.
DSA Go
current = current[1]Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next
Using unrelated pointers like .child or .parent
✗ Incorrect
In a circular linked list, each node points to the next node using the .next pointer.
2fill in blank
mediumComplete the code to check if the list has only one node.
DSA Go
if head[1] head.next {
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ==
Using comparison operators like > or < which don't apply to pointers
✗ Incorrect
If head points to itself (head == head.next), it means there is only one node in the circular linked list.
3fill in blank
hardFix the error in deleting the head node by updating the last node's next pointer.
DSA Go
last[1] = head.nextAttempts:
3 left
💡 Hint
Common Mistakes
Using .prev which points backward
Using unrelated pointers like .child or .parent
✗ Incorrect
The last node's next pointer should point to the new head, which is head.next.
4fill in blank
hardFill both blanks to correctly remove a node from the circular linked list.
DSA Go
prev[1] = current[2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next
Using unrelated pointers like .child or .parent
✗ Incorrect
To remove a node, set the previous node's next pointer to the current node's next pointer.
5fill in blank
hardFill all three blanks to complete the function that deletes a node with a given key from a circular linked list.
DSA Go
func deleteNode(head *Node, key int) *Node {
if head == nil {
return nil
}
current := head
var prev *Node
for {
if current.data == [1] {
if prev != nil {
prev[2] = current[3]
} else {
// handle deleting head node
}
break
}
prev = current
current = current.next
if current == head {
break
}
}
return head
}Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect pointer names like .prev for next pointers
Comparing with wrong variable instead of key
✗ Incorrect
We compare current.data with key to find the node to delete. Then, we update prev.next to current.next to remove the node.
