Complete the code to check if the current node is null.
if (root == [1]) return true;
We check if the node pointer is nullptr to know if we reached a leaf's child.
Complete the code to check if the current node's value is within the allowed range.
if (root->val <= [1] || root->val >= maxVal) return false;
We check if the node's value is less than or equal to minVal or greater than or equal to maxVal.
Fix the error in the recursive call to validate the left subtree.
return isValidBST(root->left, [1], root->val) && isValidBST(root->right, root->val, maxVal);
The left subtree must have values less than the current node's value, so pass minVal as lower bound and update max to root->val.
Fill both blanks to complete the function signature and initial call for BST validation.
bool isValidBST(TreeNode* root, [1] minVal = [2], long maxVal = LONG_MAX) {
The function uses long type for minVal and maxVal to handle edge cases. The initial minVal is set to LONG_MIN.
Fill all three blanks to complete the recursive BST validation logic.
if (root == nullptr) return true; if (root->val <= [1] || root->val >= [2]) return false; return isValidBST(root->left, [1], root->val) && isValidBST(root->right, root->val, [2]);
The node's value must be greater than minVal and less than maxVal. The recursive calls update these bounds accordingly.