Dsa
Binary Search Tree
Warm-up
Check for Balanced BST
You are given the root of a binary search tree (BST). Your task is to determine if the tree is height-balanced. A height-balanced tree is defined as a tree where the left and right subtrees of every node differ in height by no more than one. Implement the function `is_balanced(root)` that returns True if the tree is balanced, and False otherwise.
Input format:
The first line contains an integer N, the number of nodes in the BST.
The following N lines each contain an integer representing the value of the node.
Output format:
Boolean value (True or False) based on whether the BST is height-balanced.
Example:
Input:
5
3
9
20
15
7
Output:
True
Key concepts
binary_search_treetree_balancerecursion
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