Dsa
Binary Search Tree
Easy
Count-Balanced Nodes
A node in a BST is 'count-balanced' if the number of nodes in its left subtree is exactly equal to the number of nodes in its right subtree. Given a sequence of unique integers to build a BST, count how many nodes in the resulting tree are count-balanced. Note: Leaf nodes are always count-balanced (0 nodes on both sides).
Example:
Input: 10 5 15 2 7 12 20
Output: 7
Explanation: All 4 leaves are balanced (0=0). Nodes 5, 15, and 10 each have equal sized left and right subtrees (1=1 for 5 and 15; 3=3 for 10).
Key concepts
binary_search_treerecursiontree_structure
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