Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the same value as the current node.
DSA Go
newNode := &Node{Val: current.[1]Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'val' or 'value' which does not match the struct field.
Using 'Value' which is not the correct field name.
✗ Incorrect
The field name for the node's value is 'Val' with uppercase V in Go struct.
2fill in blank
mediumComplete the code to link the new node's next pointer to the next original node.
DSA Go
newNode.Next = current.[1]Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'next' which does not exist in the struct.
Using 'nextNode' or 'NextNode' which are not field names.
✗ Incorrect
The next pointer field in the Node struct is named 'Next' with uppercase N.
3fill in blank
hardFix the error in assigning the random pointer of the cloned node.
DSA Go
clone.Random = current.[1].NextAttempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'random' which does not match the struct field.
Using 'rand' or 'Rand' which are incorrect field names.
✗ Incorrect
The random pointer field is named 'Random' with uppercase R in the Node struct.
4fill in blank
hardFill both blanks to correctly insert cloned nodes between original nodes.
DSA Go
current.Next, current.Next.Next = current.Next[1]clone, current.Next[2]clone
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' or '+' operators which are invalid here.
Using '->' which is not valid in Go.
✗ Incorrect
In Go, to access fields of a struct pointer, use the dot operator '.'; so 'current.Next.clone' is invalid but 'current.Next.Next' is correct.
5fill in blank
hardFill all three blanks to complete the map creation for original to cloned nodes.
DSA Go
nodeMap := make(map[*Node]*Node) for current := head; current != nil; current = current.[1] { nodeMap[current] = &Node{Val: current.[2] } return nodeMap[[3]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Random' instead of 'Next' for iteration.
Using 'Random' instead of 'Val' for copying value.
Returning nodeMap with wrong key.
✗ Incorrect
We iterate using 'Next', copy the 'Val' field, and return the cloned node corresponding to 'head'.
