You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Rat in a Maze Problem](https://practice.geeksforgeeks.org/problems/rat-in-a-maze-problem/1#"view question") - [Cpp Solution](./solutions/Rat%20in%20a%20Maze%20Problem.cpp)
Given a binary tree. Find the size of its largest subtree that is a Binary Search Tree.
6
+
7
+
Example 1:
8
+
Input:
9
+
1
10
+
/ \
11
+
4 4
12
+
/ \
13
+
6 8
14
+
Output: 1
15
+
Explanation: There's no sub-tree with size
16
+
greater than 1 which forms a BST. All the
17
+
leaf Nodes are the BSTs with size equal
18
+
to 1.
19
+
20
+
Example 2:
21
+
Input: 6 6 3 N 2 9 3 N 8 8 2
22
+
6
23
+
/ \
24
+
6 3
25
+
\ / \
26
+
2 9 3
27
+
\ / \
28
+
8 8 2
29
+
Output: 2
30
+
Explanation: The following sub-tree is a
31
+
BST of size 2:
32
+
2
33
+
/ \
34
+
N 8
35
+
Your Task:
36
+
You don't need to read input or print anything. Your task is to complete the function largestBst() that takes the root node of the Binary Tree as its input and returns the size of the largest subtree which is also the BST. If the complete Binary Tree is a BST, return the size of the complete Binary Tree.
0 commit comments