Close
Topic list
Size of Largest BST in Binary Tree
EASY
10 mins
Binary Search Trees
Topics (Covered in this problem)
Problem solved
Skill meter
Binary Search Trees
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Size of Largest BST in Binary Tree

Easy
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share

## Problem Statement

#### A binary search tree (BST) is a binary tree data structure which has the following properties.

``````• The left subtree of a node contains only nodes with data less than the node’s data.
• The right subtree of a node contains only nodes with data greater than the node’s data.
• Both the left and right subtrees must also be binary search trees.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
5 2 4 1 3 -1 -1 -1 -1 -1 -1
2 1 3 -1 -1 -1 -1
``````
##### Sample Output 1:
``````3
3
``````

#### Explanation for Sample 1:

``````The BST corresponding to the first test case is-
``````

``````The subtree rooted at 2 is a BST and its size is 3.

The BST corresponding to the second test case is -
``````

``````The subtree rooted at 2 is a BST and its size is 3.
``````
##### Sample Input 2 :
``````1
50 -1 20 -1 30 -1 40 -1 50 -1 -1
``````
##### Sample Output 2:
``````4
``````
Auto
Console