Closed
Description
Check if Binary Tree is Balanced
Given the root of a binary tree, check and see if the tree is balanced. A binary tree is balanced if for every node in the tree, the height of the left and the right sub-trees differ by at most 1. This can be done in both an iterative and recursive fashion.
Solution
- Iterate through every node in the tree in a post-order traversal, calculating the height of each sub-tree for each node
- Compare the heights of the left and right sub-trees for each node in the tree and if any are greater than 1, return false, else, return true
Metadata
Metadata
Assignees
Labels
No labels