Question bank › Binary Search Tree
Dsa Binary Search Tree Medium

Mid-Range Anchor

You are given a BST representing signal frequencies. For a specific range [L, R], you want to find the 'Anchor Frequency'. The Anchor is the value present in the BST within the range [L, R] that is numerically closest to the arithmetic mean of L and R (i.e., (L+R)/2). If two values are equally close, choose the smaller one. If no value exists in the range, return -1. Input: First line contains BST nodes. Second line contains L and R. Output: The anchor frequency value. Example: Input: 10 5 20 15 25 12 24 Output: 20 Explanation: Range [12, 24]. Mean of 12 and 24 is 18. Values in BST in range: 15, 20. 15 is 3 units from 18. 20 is 2 units from 18. Closest is 20.

Key concepts

binary_search_treeoptimizationinorder_traversal

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.