FastPrepValidate Binary Search Tree
Problems/Validate Binary Search Tree

Validate Binary Search Tree

Tokopedia logoTokopedia● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names and links this well-known tree problem about strict ordering. Our version is about 99% 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, every value in its left subtree must be strictly smaller than the node's value, every value in its right subtree must be strictly greater, and both subtrees must satisfy the same rule. Duplicate values therefore make the tree invalid.

Function

isValidBST(root: TreeNode) → boolean

Examples

Example 1

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

The left child is smaller than the root and the right child is larger, so the tree is valid.

Example 2

root = [5,1,4,null,null,3,6]return = false
root
51436

Node 4 is in the root's right subtree but is smaller than root value 5.

Constraints

  • The tree contains between 1 and 10000 nodes.
  • -2147483648 <= Node.val <= 2147483647.

More Tokopedia interview questions

  • Kth Largest Element in an ArrayONSITE INTERVIEW · Seen Jul 2021
  • Online Stock SpanONSITE INTERVIEW · Seen Jul 2021
  • Vertical Order Traversal of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
  • Interleaving StringPHONE SCREEN · Seen Jul 2021
  • Delete Node in a BSTPHONE SCREEN · Seen Jul 2021
  • Rotate ImagePHONE SCREEN · Seen Jul 2021

Similar questions at other companies

  • Shortest Path Between BST NodesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Check the Order of a Binary Search TreeCapital One · ONSITE INTERVIEWCapital One interview questions
  • Add All Larger Values in a BSTAdobe · PHONE SCREENAdobe interview questions
  • Inorder Predecessor in a BSTNutanix · PHONE SCREENNutanix interview questions
  • Diagonal Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Find Leaves of a Binary TreeLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
All Tokopedia interview questionsSee Tokopedia 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…