since we have been given inorder traversal of tree and inorder of a bst is in ascending order i iterated over the inorder array and calculate the max number of consecutive elements in ascending order to be the largest bst . what is wrong in this approach ?
Largest bst in a binary tree
Hey,i would suggest you to not to solve it this way as in interview coding round you have to complete a function where you will be given a root node.Also, in interviews interview may ask you solve it without extra space since there is solution avilable that doesn’t takes extra space.
So, try to solve it recursively by actually creating the tree.
Hint:Find maximum and minimum of a nodes left subtree and right subtree and see if that relation helps to get the know whether current node’s subtree is bst or not.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.