0
0
DSA Typescriptprogramming~10 mins

Validate if Tree is BST in DSA Typescript - 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 null.

DSA Typescript
if (root [1] null) return true;
Drag options to blanks, or click blank then click option'
A!==
B===
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '===' causes incorrect null check.
Using '>' or '<' operators for null comparison.
2fill in blank
medium

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

DSA Typescript
if (root.val [1] min || root.val [2] max) return false;
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' instead of '<=' or '>=' causes boundary errors.
Checking only one side of the range.
3fill in blank
hard

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

DSA Typescript
return isValidBST(root.left, min, [1]) && isValidBST(root.right, root.val, max);
Drag options to blanks, or click blank then click option'
Aroot.val
Bmin
Cmax
Droot.left.val
Attempts:
3 left
💡 Hint
Common Mistakes
Passing min or max incorrectly causes wrong validation.
Using root.left.val instead of root.val.
4fill in blank
hard

Fill both blanks to correctly validate the right subtree with updated min.

DSA Typescript
return isValidBST(root.left, min, root.val) && isValidBST(root.right, [1], [2]);
Drag options to blanks, or click blank then click option'
Aroot.val
Bmin
Cmax
Droot.right.val
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping min and max values.
Using root.right.val instead of root.val.
5fill in blank
hard

Fill all three blanks to complete the function signature and initial call for BST validation.

DSA Typescript
function isValidBST(root: TreeNode | null, [1]: number = -Infinity, [2]: number = [3]): boolean {
  if (root === null) return true;
  if (root.val <= min || root.val >= max) return false;
  return isValidBST(root.left, min, root.val) && isValidBST(root.right, root.val, max);
}
Drag options to blanks, or click blank then click option'
Amin
Bmax
CInfinity
Droot
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting default values causes errors.
Using wrong parameter names or default values.