Dsa
Binary Search Tree
Medium
The Lonely Level Sum
Construct a BST from a sequence of integers. Identify the level (depth) of the tree that contains the minimum number of nodes. If there is a tie between multiple levels, choose the deepest one. Print the sum of the values of all nodes on that level. The root is at depth 0.
Example:
Input: 5 3 8 2 4 7 9
Depth 0: [5] (1 node)
Depth 1: [3, 8] (2 nodes)
Depth 2: [2, 4, 7, 9] (4 nodes)
The level with the minimum nodes is Depth 0. Sum is 5.
Output: 5
Key concepts
binary_search_treelevel_orderbreadth_first_search
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