DSA SectionEasy

BST

Detailed guide and Python implementation for the 'BST' problem.

Problem Statement

Easy

Write a function is_valid_bst(tree_arr) that takes an array representation of a binary tree tree_arr (root at index 0, children of i at 2i+1 and 2i+2, with None representing empty nodes) and returns True if it is a valid Binary Search Tree (BST), or False otherwise.

Constraints
  • 0 <= len(tree_arr) <= 1000

Examples

Example 1
Input
tree_arr = [2, 1, 3]
Output
True
Explanation

The left child 1 is smaller than root 2, and right child 3 is greater than root 2.

Example 2
Input
tree_arr = [5, 1, 4, None, None, 3, 6]
Output
False
Explanation

The root value is 5, but its right child 4 contains a left child 3 which is smaller than 5.

Need a Hint?
Consider using Trees-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.