Dsa
Binary Search Tree
Easy
Count Nodes in Range
Given a Binary Search Tree (BST) and a range [low, high], count the number of nodes that have values within that range. The input comprises the serialized representation of the tree and the two integers for the range. For the purposes of this problem, the binary tree is serialized in level order and null nodes are represented by a '-1'.
Input format:
- The first line contains integers separated by space: the level order traversal of the tree.
- The second line contains two integers, low and high.
Output format:
- A single integer representing the count of nodes with values within the range [low, high].
Example:
Input:
2 1 3 -1 -1 -1 -1
1 2
Output:
1
Key concepts
binary_search_treetraversalrange_query
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