Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given data.
DSA Go
newNode := &Node{data: [1], next: nil, prev: nil}Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the function.
Using 'data' instead of the parameter name.
✗ Incorrect
The variable 'd' holds the data to insert, so it should be assigned to the new node's data field.
2fill in blank
mediumComplete the code to check if the list is empty.
DSA Go
if head == [1] {
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'null' which is not valid in Go.
Using 0 or 'empty' which are not pointer values.
✗ Incorrect
In Go, 'nil' is used to check if a pointer is empty or not initialized.
3fill in blank
hardFix the error in the loop that finds the last node.
DSA Go
for current.[1] != nil { current = current.next }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which moves backward in the list.
Using undefined fields like 'nextNode' or 'pointer'.
✗ Incorrect
To move forward in the list, we check and use the 'next' pointer of the current node.
4fill in blank
hardFill both blanks to correctly link the new node at the end.
DSA Go
current.next = [1] [2].prev = current
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for the new node.
Forgetting to set the prev pointer of the new node.
✗ Incorrect
The new node is assigned to current.next, and its prev pointer is set to current.
5fill in blank
hardFill all three blanks to return the head of the updated list.
DSA Go
if head == nil { head = [1] return [2] } return [3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names for the new node.
Returning the new node instead of head when list is not empty.
✗ Incorrect
When the list is empty, head is set to newNode and returned. Otherwise, the original head is returned.
