Validate a Strict Binary Search Tree
Updated
Problem statement
You are given the root of a binary tree. Return true if it is a binary search tree, and false if it is not.
Use the strict rule. Every value in a node's whole left subtree must be smaller than the node's value. Every value in its whole right subtree must be larger. Equal values are not allowed. An empty tree counts as valid.
Function
isStrictBST(root: TreeNode) → booleanExamples
Example 1
root = [2,1,3]return = trueThe left child is smaller than the root, and the right child is larger. So the tree is valid, and the answer is true.
Example 2
root = [5,1,4,null,null,3,6]return = falseThe right subtree holds 4 and 3. Every value there must be larger than the root 5, but these two are smaller. So the tree is not valid, and the answer is false.
Example 3
root = []return = trueThe tree is empty, and an empty tree counts as valid. The answer is true.
Constraints
- The tree has
0to500nodes. -10^9 <= node.val <= 10^9.
More Amazon Phone Screen questions
- Count Connected ComponentsPHONE SCREEN · Seen Dec 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Merge Accounts by Shared AttributePHONE SCREEN · Seen Dec 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge k Sorted ListsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 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