Solution Review: Is It a BST Array?
Let’s take a detailed look at the previous challenge’s solution.
We'll cover the following
Solution
In pre-order traversal, we first visit the root, then the left child, and finally the right child. So, once we find a value greater than the root
value, we are in the right subtree. Therefore, all the nodes that we’ll traverse now will have values greater than the root
value. We’ll use this logic to code our solution.
Solution code
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.