Search⌘ K
AI Features

Problem: Range Sum of BST

Explore how to calculate the sum of nodes within a specified range in a binary search tree using Go. Understand how to leverage BST properties to prune unnecessary branches for efficient recursion. This lesson teaches you to implement a recursive range sum function, analyze time and space complexity, and apply problem-solving skills with BSTs.

Statement

You are given the root of a binary search tree (BST) along with two integers low and high. Compute and return the sum of all node values that fall within the inclusive range [low, high].

Note: All node values in the BST are unique.

Constraints:

  • The number of nodes in the tree is in the range [1,2×104][1, 2 \times 10^4]. ...