Back to Practice Dashboard
DSA SectionEasy
BST
Learn how to solve the 'BST' problem. This detailed resource details brute force and optimized approaches.
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?
Perform a recursive tree traversal (DFS) or level-order traversal (BFS) using a queue/stack.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.