You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Given a binary search tree, replace each nodes' data with the sum of all nodes' which are greater or equal than it. Include the current node's data also.
7
+
8
+
// Input Format
9
+
// The first line contains a number n showing the length of the inorder array of BST. The next line contains n integers denoting the elements of the array.
10
+
11
+
// Constraints
12
+
// 2 ≤ N ≤ 10^3
13
+
14
+
// Output Format
15
+
// Print the preorder traversal of the new tree.
16
+
17
+
// Sample Input
18
+
// 7
19
+
// 20 30 40 50 60 70 80
20
+
// Sample Output
21
+
// 260 330 350 300 150 210 80
22
+
// Explanation
23
+
// The original tree looks like
24
+
25
+
// 50
26
+
// / \
27
+
// 30 70
28
+
// / \ / \
29
+
// 20 40 60 80
30
+
// We are supposed to replace the elements by the sum of elements larger than it.
31
+
// 80 being the largest element remains unaffected .
32
+
// 70 being the second largest element gets updated to 150 (70+80)
0 commit comments