Dsa
Binary Search Tree
Easy
Total Nodes within Range
Given a binary search tree, count the number of nodes that fall within a specified range [low, high].
Input Format:
The first line contains an integer n, the number of nodes in the BST.
The next n lines contain integers representing the nodes to be inserted into the BST.
The last line contains two integers, low and high, that define the range.
Output Format:
Print the count of nodes within the specified range.
Example:
Input:
5
10
5
15
3
7
5 12
Output:
3
Key concepts
binary_search_treerange_querycount_nodes
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