DIY: Range Sum of BST

Solve the interview question "Range Sum of BST" in this lesson.

Problem statement

For this challenge, you are given the root node of a binary search tree and two values: low and high. Your task is to return the sum of the values of all nodes in BST that are value between low and high. The nodes with values equal to low or high should be included in the sum.


The function will have three parameters: root, low, and high. The root will be the root node of a binary search tree containing integer values. The binary tree will not have any repetitive values. The parameters low and high will also be integers.

For example, consider the following BST’s root as input. The values of high and low are also given below:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.