Solution Review: Is It a BST?

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

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.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.