0
0
DSA Goprogramming~10 mins

Validate if Tree is BST 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 nil.

DSA Go
if [1] == nil {
    return true
}
Drag options to blanks, or click blank then click option'
Anode
Broot
Ctree
DrootNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' instead of 'node' causes confusion in recursion.
Checking for 'tree' or 'rootNode' which are not defined in this scope.
2fill in blank
medium

Complete the code to check if the current node's value is within the allowed range.

DSA Go
if node.Val <= [1] || node.Val >= [2] {
    return false
}
Drag options to blanks, or click blank then click option'
Amin
Bmax
Cleft
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' or 'right' instead of min and max confuses the range check.
Using >= for min or <= for max reverses the logic.
3fill in blank
hard

Fix the error in the recursive call to validate the left subtree with updated max boundary.

DSA Go
return isValidBSTHelper(node.Left, [1], node.Val) && isValidBSTHelper(node.Right, node.Val, [2])
Drag options to blanks, or click blank then click option'
Amin
Bnode.Val
Cmax
Dnil
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping min and max in recursive calls.
Passing nil instead of boundaries causes runtime errors.
4fill in blank
hard

Fill both blanks to initialize the min and max values for the first call to isValidBST.

DSA Go
func isValidBST(root *TreeNode) bool {
    return isValidBSTHelper(root, [1], [2])
}
Drag options to blanks, or click blank then click option'
Amath.MinInt64
Bmath.MaxInt64
C0
Dnil
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 for boundaries restricts valid values incorrectly.
Using nil causes type errors in Go.
5fill in blank
hard

Fill all three blanks to complete the helper function signature and recursive calls correctly.

DSA Go
func isValidBSTHelper(node *TreeNode, [1] int64, [2] int64) bool {
    if node == nil {
        return true
    }
    if node.Val <= [1] || node.Val >= [2] {
        return false
    }
    return isValidBSTHelper(node.Left, [1], node.Val) && isValidBSTHelper(node.Right, node.Val, [2])
}
Drag options to blanks, or click blank then click option'
Amin
Bmax
Cval
DnodeVal
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names causes confusion.
Passing wrong variables in recursive calls.