Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the result slice for storing the right side view nodes.
DSA Go
result := [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a map instead of a slice.
Initializing with nil instead of an empty slice literal.
✗ Incorrect
We use an empty slice of integers to store the right side view nodes dynamically.
2fill in blank
mediumComplete the code to append the rightmost node's value at each level to the result slice.
DSA Go
result = append(result, [1].Val) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' which is always the tree root.
Using 'queue[0]' which may not be the current node.
✗ Incorrect
We append the value of the current node being processed at the rightmost position of the level.
3fill in blank
hardFix the error in the loop condition to process nodes level by level.
DSA Go
for len([1]) > 0 {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking length of result which is unrelated to loop control.
Using stack which is not used here.
✗ Incorrect
The queue holds nodes to process; loop continues while queue is not empty.
4fill in blank
hardFill both blanks to correctly enqueue the left child of the current node.
DSA Go
if [1] != nil { queue = append(queue, [2]) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Appending right child when checking left child.
Appending nil nodes.
✗ Incorrect
We check if the left child exists and then append it to the queue.
5fill in blank
hardFill all three blanks to enqueue the right child after the left child inside the loop.
DSA Go
if [1] != nil { queue = append(queue, [2]) } if [3] != nil { queue = append(queue, current.Right) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing left and right child checks.
Appending nil children.
✗ Incorrect
First check and append left child, then check and append right child to the queue.