You are viewing a single comment's thread. Return to all comments →
Here is the Logic
The Inorder Traversal of the Binary Search Tree gives you the sorted array.
if tree is something like this
then its Inorder Traversal would be
A, B, C, D, E, F, G, H, I.
and now I have checked if the i th element is greater than its previous (i-1)th element
if the loop is over then return true
there is a violation and the tree isnt BST so return false