Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

125. Validate Binary Search Tree

MediumDay 37 of 60Trees & BST

Given the root of a binary tree, return true if it is a valid binary search tree. In a valid BST, every value in a node's left subtree is strictly smaller than the node, every value in its right subtree is strictly larger, and both subtrees are valid BSTs themselves.

Example 1
Input: root = [2,1,3]
Output: true
Example 2
Input: root = [5,1,4,null,null,3,6]
Output: false
The root is 5 but its right child is 4, which is smaller.
Constraints
  • The number of nodes is in the range 1 to 10^4
  • -2^31 <= Node.val <= 2^31 - 1
Hints
Frequently asked at: Amazon, Microsoft, Meta, Bloomberg, Adobe
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min