0
0
DSA Goprogramming~10 mins

Path Sum Root to Leaf in 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 check if the current node is a leaf node.

DSA Go
if root.Left == nil && root.[1] == nil {
Drag options to blanks, or click blank then click option'
AChild
BRight
CParent
DNext
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for Parent or Next instead of Right child.
Using incorrect field names.
2fill in blank
medium

Complete the code to subtract the current node's value from the sum.

DSA Go
return hasPathSum(root.Left, sum - root.[1]) || hasPathSum(root.Right, sum - root.Val)
Drag options to blanks, or click blank then click option'
ANum
BValue
CData
DVal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Value' or 'Data' which are not valid field names.
Using 'Num' which is not defined.
3fill in blank
hard

Fix the error in the base case to correctly return false when the node is nil.

DSA Go
if root == [1] {
    return false
}
Drag options to blanks, or click blank then click option'
Anil
B0
Cnull
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'null' or 'None' instead of 'nil'.
Using 0 which is not a pointer.
4fill in blank
hard

Fill both blanks to correctly check if the current node is a leaf and if the sum matches the node's value.

DSA Go
if root.Left == nil && root.Right == nil {
    return sum == root.[1] 
} else {
    return hasPathSum(root.[2], sum - root.Val) || hasPathSum(root.Right, sum - root.Val)
}
Drag options to blanks, or click blank then click option'
AVal
BLeft
CRight
DData
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Data' instead of 'Val'.
Using 'Right' for the first recursive call instead of 'Left'.
5fill in blank
hard

Fill all three blanks to complete the recursive calls checking both children with updated sums.

DSA Go
return hasPathSum(root.[1], sum - root.[2]) || hasPathSum(root.[3], sum - root.Val)
Drag options to blanks, or click blank then click option'
ALeft
BVal
CRight
DData
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Data' instead of 'Val'.
Mixing up child pointers in recursive calls.