Question bank › Binary Search Tree
Dsa Binary Search Tree Hard

Closest BST Value

Given a binary search tree and a value, find the value in the BST that is closest to the given target. The tree is represented as a series of space-separated integers on one line, where 'x' indicates a null node. Print the closest value to the target. If multiple values are equally close, print the smallest one. The first line contains the integer target, and the second line contains the tree nodes. Example input/output is shown below. Input: 5 4 2 7 1 3 x x x x x x Output: 4

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
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.