Tap here to switch tabs
Problem
Submissions

Problem: Convert BST to Greater Tree

Try to solve the Convert BST to Greater Tree problem.

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

Try to solve the Convert BST to Greater Tree problem.

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.