Dsa
Binary Search Tree
Warm-up
Check if BST is Balanced
You are given the root of a binary search tree (BST). Your task is to determine whether the BST is height-balanced. A height-balanced tree is defined as a tree where the depths of the two subtrees of any node never differ by more than one.
Input Format:
- The first line contains an integer n, the number of nodes in the BST.
- The next n lines each contain a single integer, which represents the value of the node inserted into the BST.
Output Format:
- Print "YES" if the BST is balanced and "NO" otherwise.
Example:
Input:
5
10
5
15
3
7
Output:
YES
Key concepts
binary_search_treetree_balance
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