Dsa
Binary Search Tree
Warm-up
Warehouse Price Audit
You are auditing a warehouse where items are stored in a Binary Search Tree based on their unique ID. Each node's ID is used as the key. Given a sequence of IDs to build the BST (inserting in the order provided), and a price range [L, R], count how many items in the warehouse have IDs that fall within that inclusive range.
Input Format:
Line 1: A space-separated list of integers representing the IDs to be inserted into the BST (starting with the root).
Line 2: Two space-separated integers, L and R.
Output Format:
A single integer representing the count of IDs where L <= ID <= R.
Example:
Input:
10 5 15 3 7 12 18
7 13
Output:
3
(The IDs 7, 10, and 12 fall in the range [7, 13])
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