Question bank › Binary Search Tree
Dsa Binary Search Tree Medium

Sum of Values in BST Range

Given a binary search tree (BST) and a range [low, high], calculate the sum of all the values in the BST that fall within this range. Write a program that reads a series of integers representing the values of nodes in the BST, followed by two integers indicating the range limits. The first integer in the series is the root node of the BST, and subsequent integers are inserted according to the rules of a BST. Input format: - The first line contains integers separated by spaces, representing values to be inserted into the BST. - The second line contains two integers, low and high, separated by a space. Output format: - Output the sum of all values in the BST that fall within the range [low, high]. Example: Input: 10 5 15 3 7 18 7 15 Output: 32

Key concepts

binary_search_treerange_sumrecursion

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