Back to Practice Dashboard
DSA SectionMedium

AVL Tree

Learn how to solve the 'AVL Tree' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Medium

Write a function is_avl_balanced(tree_arr) that takes an array representation of a binary tree tree_arr and returns True if the tree is height-balanced (for every node, the height of its left and right subtrees differs by at most 1) and is a valid BST, or False otherwise.

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

Examples

Example 1
Input
tree_arr = [3, 9, 20, None, None, 15, 7]
Output
True
Explanation

The tree is a valid BST and the depth difference of left/right subtrees of all nodes is at most 1.

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

The tree is unbalanced because leaf node 4 is at depth 4 while right subtree of node 1 is empty.

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.

Open in Editor