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], next: nil}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 int type.
✗ Incorrect
We create a new node with data set to the given value.
2fill in blank
mediumComplete the code to link the new node to the current head of the list.
DSA Go
newNode.next = [1]Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to value instead of head.
Setting next to nil which breaks the list.
✗ Incorrect
The new node's next pointer should point to the current head node.
3fill in blank
hardFix the error in updating the head pointer to the new node.
DSA Go
head = [1]Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to value or nil instead of newNode.
Assigning head to head.next which skips the new node.
✗ Incorrect
After pushing, the head should point to the new node.
4fill in blank
hardFill both blanks to complete the push function that inserts a new node at the front.
DSA Go
func push(head **Node, value int) {
newNode := &Node{data: [1], next: *head}
*head = [2]
}Attempts:
3 left
💡 Hint
Common Mistakes
Not using pointer dereference for head update.
Setting next to head instead of *head.
✗ Incorrect
We create a new node with data as value and next pointing to current head, then update head to newNode.
5fill in blank
hardFill all three blanks to implement push that adds a new node at the front of the list.
DSA Go
func push(head **Node, value int) {
newNode := &Node{data: [1], next: [2]
[3] = newNode
}Attempts:
3 left
💡 Hint
Common Mistakes
Confusing head and *head when updating pointers.
Setting next to head instead of *head.
Assigning head instead of *head to newNode.
✗ Incorrect
We set newNode data to value, next to *head (current head), then update *head to newNode.
