FastPrepValidate a Strict Binary Search Tree
Problems/Validate a Strict Binary Search Tree

Validate a Strict Binary Search Tree

Meta logoMeta● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta phone screen. The original report names BST validation and gives an approach with strict lower and upper limits. We chose the answer for an empty tree and the limits. Our version is about 95% the same as the reported question.

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) → boolean

Examples

Example 1

root = [2,1,3]return = true
root
213

Every 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 = false
root
51748

Node 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 = false
root
223

The left child equals the root. The comparison must be strict, so this tree is invalid.

Example 4

root = []return = true
root
empty

The empty tree contains no violation.

Constraints

  • For this exercise, assume the tree contains between 0 and 2000 nodes.
  • Node values are signed 32-bit integers: -2147483648 <= node.val <= 2147483647.
  • The input is a valid binary tree. Displayed arrays use level order with null for 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
All Meta interview questionsSee Meta hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isValidBST(TreeNode root) {
        // Write your code here.
    }
}
Checking account…