Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a node's left child value is less than the node's value.
DSA Java
if (node.left != null && node.left.value [1] node.value) { // valid left child }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for left child comparison.
Using '==' which only checks equality, not order.
✗ Incorrect
In a BST, the left child's value must be less than the node's value.
2fill in blank
mediumComplete the code to check if a node's right child value is greater than the node's value.
DSA Java
if (node.right != null && node.right.value [1] node.value) { // valid right child }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for right child comparison.
Using '==' which only checks equality, not order.
✗ Incorrect
In a BST, the right child's value must be greater than the node's value.
3fill in blank
hardFix the error in the BST validation condition for the left subtree.
DSA Java
return (node.left == null || node.left.value [1] node.value) && isValidBST(node.left) && isValidBST(node.right);
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' or '<=' which allow equal values and break strict BST rules.
Using '>' which reverses the condition.
✗ Incorrect
The left subtree values must be strictly less than the node's value to maintain BST property.
4fill in blank
hardFill both blanks to complete the BST validation for left and right children.
DSA Java
return (node.left == null || node.left.value [1] node.value) && (node.right == null || node.right.value [2] node.value);
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-strict comparisons like '<=' or '>=' which allow duplicates.
Swapping the operators for left and right children.
✗ Incorrect
Left child values must be less than node's value, right child values must be greater.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps node values to their left or right child check.
DSA Java
Map<Integer, Boolean> check = Map.of(
[1], node.left != null && node.left.value [2] node.value,
[3], node.right != null && node.right.value [2] node.value
);Attempts:
3 left
💡 Hint
Common Mistakes
Using the same key for both map entries.
Using wrong comparison operators for left or right child.
✗ Incorrect
Map keys are left and right child values; left child must be less than node, right child greater.
