Tap here to switch tabs
Problem
Submissions

Problem: Convert BST to Greater Tree

Convert BST to Greater Tree replaces each node's value with its original value plus every greater value in the binary search tree, then returns the modified root.

Statement

Given the root of a Binary Search Tree (BST), convert it into a Greater Tree such that each node’s value is replaced with the sum of its original value and the values of all nodes in the tree that are greater than it.

Return the root of the modified tree.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4

  • All the values in the tree are unique.

  • root is guaranteed to be a valid binary search tree.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Convert BST to Greater Tree

Convert BST to Greater Tree replaces each node's value with its original value plus every greater value in the binary search tree, then returns the modified root.

Statement

Given the root of a Binary Search Tree (BST), convert it into a Greater Tree such that each node’s value is replaced with the sum of its original value and the values of all nodes in the tree that are greater than it.

Return the root of the modified tree.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4

  • All the values in the tree are unique.

  • root is guaranteed to be a valid binary search tree.