Skip to the content.

Asked by Google

Question

Given a binary search tree and a range [a, b] (inclusive), return the sum of the elements of the binary search tree within the range.

For example, given the following tree:

    5
   / \
  3   8
 / \ / \
2  4 6 10 `and the range `[4, 9]`, return `23` (5 + 4 + 6 + 8).`