Dsa
Binary Search Tree
Easy
Find Closest Value in BST
Given a binary search tree and a target value, find the value in the BST that is closest to the target. If two values are equally close, return the smaller value.
The input format is as follows: The first line contains the target value (float), followed by the inorder representation of the BST as a list of integers. Each integer represents a node in the BST.
Example Input:
3.7
[5, 2, 8, 1, 3, 7]
Example Output:
3
Key concepts
binary_search_treesearchclosest_value
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