Given a binary tree, I want to find out the largest subtree which is a BST in it.
Naive approach:
I have a naive approach in mind where I visit every node of
This isn't the most optimal approach but you could do an inorder traversal of the Binary tree and store it in an array and then find the longest contiguous increasing sequence, that will give you the BST with the maximum number of nodes. The complexity would be O(n) for the traversal and O(n) for the search so it's still going to be O(n).