Validate a Strict Binary Search Tree
Updated
Problem statement
Given the root of a binary tree, return whether it is a valid binary search tree.
For every node, all values in its left subtree must be strictly smaller than its value, and all values in its right subtree must be strictly larger. Both subtrees must satisfy the same rule. Equal values are not allowed, including duplicates separated by several edges.
For this exercise, assume an empty tree is valid. Check the entire tree; comparing only each node with its immediate children is insufficient.
Function
isValidBST(root: TreeNode) → booleanExamples
Example 1
root = [2,1,3]return = trueEvery left-subtree value is smaller and every right-subtree value is larger than its ancestor.
Example 2
root = [5,1,7,null,null,4,8]return = falseNode 4 is smaller than its parent 7, but it lies in the right subtree of 5 and must be larger than 5.
Example 3
root = [2,2,3]return = falseThe left child equals the root. The comparison must be strict, so this tree is invalid.
Example 4
root = []return = trueThe empty tree contains no violation.
Constraints
- For this exercise, assume the tree contains between
0and2000nodes. - Node values are signed 32-bit integers:
-2147483648 <= node.val <= 2147483647. - The input is a valid binary tree. Displayed arrays use level order with
nullfor absent children.
More Meta Phone Screen questions
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
- Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Values Exclusive to the Current UserPHONE SCREEN · Seen Sep 2026
- First Bad Version in a Monotone ArrayPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- House Robber IIIOkta · PHONE SCREENOkta interview questions
- Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Validate Binary Search TreeKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
- House Robber IIIVisa · PHONE SCREENVisa interview questions
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
- Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences