Solution Review: Is It a BST Array?

Let’s take a detailed look at the previous challenge’s solution.

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

Get hands-on with 1400+ tech skills courses.