1038. Binary Search Tree to Greater Sum Tree

Medium

Problem:

Given a binary search tree, calculate the sum of nodes with values between low and high, inclusive.

https://leetcode.com/problems/binary-search-tree-to-greater-sum-treearrow-up-right

Solution:

To find a value that is equal to or greater than oneself, you can simply compute the sum of the right child node, including oneself. This is because, in the BST structure, the right child node always has a value greater than the parent node.

Since we move in the order of 'right-parent-left', we can recognize that it corresponds to an in-order traversal starting from the right child.

Last updated