0
0
DSA Goprogramming~10 mins

Right Side View of Binary Tree in DSA Go - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Anil
Bmap[int]int{}
Cmake([]int, 0, 10)
D[]int{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a map instead of a slice.
Initializing with nil instead of an empty slice literal.
2fill in blank
medium

Complete 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'
Anode
Broot
Ccurrent
Dqueue[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' which is always the tree root.
Using 'queue[0]' which may not be the current node.
3fill in blank
hard

Fix 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'
Astack
Bqueue
Cnodes
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Checking length of result which is unrelated to loop control.
Using stack which is not used here.
4fill in blank
hard

Fill 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'
Acurrent.Left
Bcurrent.Right
Attempts:
3 left
💡 Hint
Common Mistakes
Appending right child when checking left child.
Appending nil nodes.
5fill in blank
hard

Fill 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'
Acurrent.Left
Ccurrent.Right
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing left and right child checks.
Appending nil children.