Dsa
Binary Search Tree
Hard
Balanced BST Insertion and Height Calculation
You are tasked with implementing a balanced binary search tree (BST). The tree must maintain balance as new elements are added to it. Your program should read a list of integers, insert them into the BST, and then calculate the height of the tree. The height of an empty tree is defined as -1.
Input Format:
- A single line containing space-separated integers representing the values to be inserted into the BST.
Output Format:
- A single integer representing the height of the balanced BST.
Example:
Input:
5 3 7 1 4 6 8
Output:
2
Key concepts
binary_search_treeinsertionheight
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