Solution Review: Is It a BST?
Let’s take a detailed look at the previous challenge’s solution.
We'll cover the following
Solution
We’ll check the following conditions at each node:
- The maximum value of the left subtree is smaller than the value of the current node.
- The minimum value of the right subtree is greater than the current node.
If these conditions are fulfilled, then the given binary tree is a BST. The following code demonstrates this approach.
Get hands-on with 1400+ tech skills courses.