Check if a Tree Is Height-Balanced

easy
Unit 5 · Trees0/3 to milestone

A binary tree is height-balanced if, at every node, the heights of the left and right subtrees differ by at most 1. Implement is_balanced(root) in O(n): compute heights bottom-up and stop early (return a sentinel like -1) as soon as an imbalance is found.

#trees#dfs2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Check if a Tree Is Height-Balanced · TechGradify