Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current node is null.
DSA Javascript
function isBST(node) {
if (node [1] null) {
return true;
}
// further checks
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of === causes incorrect base case handling.
Using logical operators instead of comparison.
✗ Incorrect
We check if the node is exactly equal to null to handle the base case of recursion.
2fill in blank
mediumComplete the code to check if the left child's value is less than the current node's value.
DSA Javascript
if (node.left !== null && node.left.val [1] node.val) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >= causes wrong validation.
Using equality check instead of comparison.
✗ Incorrect
For a BST, left child's value must be less than the current node's value. If it is greater or equal, return false.
3fill in blank
hardFix the error in the recursive call to validate the right subtree with updated min value.
DSA Javascript
return isBST(node.left, min, node.val) && isBST(node.right, [1], max);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing min instead of node.val causes incorrect range checks.
Passing max instead of min for right subtree.
✗ Incorrect
For the right subtree, the minimum allowed value is the current node's value.
4fill in blank
hardFill both blanks to complete the function signature and initial call for BST validation.
DSA Javascript
function isBST(node, [1] = -Infinity, [2] = Infinity) { if (node === null) return true; // validation logic }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names causes confusion.
Swapping min and max values.
✗ Incorrect
The function uses min and max to keep track of valid value ranges for nodes.
5fill in blank
hardFill all four blanks to complete the BST validation condition inside the function.
DSA Javascript
if (node.val [1] [2] || node.val [3] [4]) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Swapping min and max in conditions.
✗ Incorrect
The node's value must be greater than min and less than max to be valid in BST.