Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Go
newNode := &Node{data: [1]Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' instead of the value for the new node's data.
Setting data to nil which is invalid for an int field.
✗ Incorrect
We create a new node with the data field set to the given value.
2fill in blank
mediumComplete the code to handle the empty list case by pointing newNode's next to itself.
DSA Go
if head == nil { newNode.next = [1] head = newNode }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to nil breaks the circular property.
Setting next to head when head is nil causes nil pointer errors.
✗ Incorrect
In a circular linked list with one node, the node points to itself.
3fill in blank
hardFix the error in the loop that finds the last node in the circular list.
DSA Go
last := head for last.next != [1] { last = last.next }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing last.next to nil causes infinite loop.
Comparing last.next to newNode is incorrect before insertion.
✗ Incorrect
The last node points back to head in a circular linked list.
4fill in blank
hardFill both blanks to insert newNode at the beginning and update the last node's next pointer.
DSA Go
newNode.next = [1] last.next = [2]
Attempts:
3 left
💡 Hint
Common Mistakes
Setting last.next to head instead of newNode breaks the list.
Setting newNode.next to nil breaks circular property.
✗ Incorrect
newNode points to old head; last node points to newNode to maintain circularity.
5fill in blank
hardFill both blanks to update head and complete the insertion at beginning.
DSA Go
head = [1] return [2] // Function signature: func insertAtBeginning(head *Node, value int) *Node { // Node struct: type Node struct { data int; next *Node } // }
Attempts:
3 left
💡 Hint
Common Mistakes
Returning old head instead of newNode.
Returning nil causes loss of list reference.
✗ Incorrect
Head is updated to newNode; function returns newNode; no extra return needed.
