Validate Binary Search Tree With Python

The Prompt

Create a function that takes in a Binary Search Tree (BST), it may be invalid, and returns a boolean value representing whether the BST is valid.

The Code

Let’s start off by initiating the BST class and creating a template for our solution.

  • if the tree’s value is less than the minimum value (minVal) OR is greater than the maximum value (maxVal), then return FALSE

Complexity Analysis

The time complexity of this solution will be O(n) time, where (n) is the length of the BST.