FastPrepIs This Binary Tree a BST
Problems/Is This Binary Tree a BST

Is This Binary Tree a BST

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You check whether the values of a tree keep the search-tree order. Two Adobe reports ask for it. The first is a May 2022 post about on-campus MTS hiring. It links this classic task as the second question of its first technical round, after a project talk and a jump-game question. That round also covered running time for each of its two questions. For this one, the author reports a working answer, followed by a request for a change to it that the post does not describe. The second is a post from June 2022 (seven months of experience, off-campus MTS opening). It has the check right after a task on halving numbers in its earliest live interview (5 May 2022, about 50 minutes). There it is a single line with no rules, limits or examples.

The rules are those of the linked task. The order is strict on both sides, so a repeated value makes the tree invalid. We chose these limits: 1 to 500 nodes, with values across the full 32-bit range. We wrote new examples.

Our version is about 90% the same as the reported questions.

Given the root of a binary tree, return true if it is a binary search tree, and false otherwise.

A binary tree is a binary search tree when, for every node, every value in its left subtree is strictly smaller than the node's value and every value in its right subtree is strictly larger. Checking only a node's two children is not enough: the rule covers the whole subtree. A value that appears twice makes the answer false.

Function

isValidBst(root: TreeNode) → boolean

Examples

Example 1

root = [8,4,12,2,6,10,14]return = true
root
8426121014

Every node is larger than everything on its left and smaller than everything on its right (for example, the root 8 has 2, 4, 6 on its left and 10, 12, 14 on its right), so the answer is true.

Example 2

root = [8,4,12,2,9]return = false
root
842912

9 is the right child of 4, which is fine for 4, but 9 sits in the left subtree of the root 8 and is larger than 8. So the answer is false.

Example 3

root = [7,7]return = false
root
77

The left child has the same value as the root. Values on the left must be strictly smaller, so the answer is false.

Constraints

  • The tree has 1 to 500 nodes.
  • -2^31 <= Node.val <= 2^31 - 1

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Inorder Predecessor in a BSTNutanix · PHONE SCREENNutanix interview questions
  • Shortest Path Between BST NodesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Validate Binary Search TreeTokopedia · ONSITE INTERVIEWTokopedia interview questions
  • Check the Order of a Binary Search TreeCapital One · ONSITE INTERVIEWCapital One interview questions
  • 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

Interview reports that mention this question

  • Adobe New Grad MTS Interview Questions: 7 Experiences

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)
All Adobe interview questionsSee Adobe 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…