Dsa
Trees
Easy
Balanced Tree Checker
Write a function to check if a binary tree is balanced. A balanced tree is defined as a tree in which the height of the two subtrees of any node never differs by more than one.
Input format:
- The first line contains an integer N, the number of nodes.
- The next N lines contain the values of the nodes in level-order traversal, where 'null' represents an empty node.
Output format:
- Print True if the tree is balanced, otherwise print False.
Example:
Input:
5
1
2
3
null
null
4
5
Output:
False
Key concepts
treesbalancedheight
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now