Dsa
Binary Search Tree
Warm-up
Inventory Shelf Depth
In a smart library, books are indexed in a BST by their unique serial number. The 'depth' of a book determines which shelf height it is on (the root is at depth 0, its children at depth 1, etc.). Given a sequence of serial numbers to build a BST and a target serial number, find the depth of that target. If the serial number is not in the tree, output -1.
Input Format:
Line 1: Space-separated integers representing the serial numbers in insertion order.
Line 2: A single integer representing the target serial number.
Output Format:
An integer representing the depth, or -1 if not found.
Example:
Input:
50 30 70 20 40 60 80
60
Output:
2
Key concepts
binary_search_treesearchtree_depth
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