Dsa
Binary Search Tree
Hard
Find Median in BST
Create a program that reads a Binary Search Tree (BST) and computes the median value of all its nodes. The input consists of a list of integers representing the pre-order traversal of the BST, with '-1' representing a null node. The median is defined as the middle value when the nodes are sorted. If the number of nodes is even, return the average of the two middle values. Output the median.
Example Input:
7 3 -1 -1 9 -1 -1 5 -1 -1
Example Output:
5
Key concepts
binary_search_treemedianorder_statistics
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