Validate That a User ID Index Tree Is a Proper BST
Last updated: November 29, 2026
Quick Overview
Given the root of a binary tree that should index user IDs, return whether it is a valid binary search tree: every node's left subtree holds strictly smaller IDs and right subtree strictly larger IDs.
Meta
November 29, 20260
0
0 solved
Given the root of a binary tree that should index user IDs, return whether it is a valid binary search tree: every node's left subtree holds strictly smaller IDs and right subtree strictly larger IDs.
A Meta technical screen classic chosen because the tempting check (each node against only its children) is wrong. The interviewer wants a bounds-passing DFS or an inorder traversal and a clear counterexample for the naive version.
What the Interviewer Expects
- Show the counterexample to parent-child-only checks
- Pass down a (low, high) open interval
- Or verify that inorder traversal is strictly increasing
- Handle duplicates per the stated rule
- Use an iterative traversal for deep trees
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if duplicates are allowed on the right side?
- How would you find the two nodes that were swapped if it is invalid?
- How would you find the largest valid BST subtree?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is a binary tree root or None. Return True if for every node, all values in its left subtree are strictly less and all values in its right subtree strictly greater. Duplicates are invalid. An em...
High-Level Design
Checking only left.val < node.val < right.val misses cases like root 5 with right child 6 whose left child is 3: 3 is less than 6 but sits in 5's right subtree.
The clean property: an inorder trave...