Tap here to switch tabs
Problem
Submissions

Problem: Binary Search Tree to Greater Sum Tree

Try to solve the Binary Search Tree to Greater Sum Tree problem.

Statement

Given the root of a Binary Search Tree (BST), convert it into a Greater Sum Tree (GST).

In a Greater Sum Tree, the value of each node is updated to be the sum of its original value plus the sum of all keys in the original BST that are greater than the node’s original value.

Recall that a Binary Search Tree satisfies the following conditions:

  • The left subtree of a node contains only nodes with keys strictly less than the node’s key.

  • The right subtree of a node contains only nodes with keys strictly greater than the node’s key.

  • Both the left and right subtrees must also be binary search trees.

Constraints:

  • The number of nodes in the tree is in the range [1,100][1, 100].

  • 0≤0 \leq Node.val ≤100\leq 100

  • All the values in the tree are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Binary Search Tree to Greater Sum Tree

Try to solve the Binary Search Tree to Greater Sum Tree problem.

Statement

Given the root of a Binary Search Tree (BST), convert it into a Greater Sum Tree (GST).

In a Greater Sum Tree, the value of each node is updated to be the sum of its original value plus the sum of all keys in the original BST that are greater than the node’s original value.

Recall that a Binary Search Tree satisfies the following conditions:

  • The left subtree of a node contains only nodes with keys strictly less than the node’s key.

  • The right subtree of a node contains only nodes with keys strictly greater than the node’s key.

  • Both the left and right subtrees must also be binary search trees.

Constraints:

  • The number of nodes in the tree is in the range [1,100][1, 100].

  • 0≤0 \leq Node.val ≤100\leq 100

  • All the values in the tree are unique.