FastPrepAdd All Larger Values in a BST
Problems/Add All Larger Values in a BST

Add All Larger Values in a BST

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem replaces each value in a BST with that value plus all larger values added together. Two Adobe reports ask for it. One post from May 2022 (4.5 years of experience, CS1 offer, Bangalore) lists only two practice-problem links for its first round, with no other text. One is this classic task, and the other is the rotting-oranges grid task. The other report is a post from June 2025 about a June 2022 off-campus process. There, this was one of three coding questions in a first round that also tested CS fundamentals. The author reports a working version that leaves out the node's own value, so only strictly larger values are added. That report calls the input a binary tree, not a BST.

The rules here are those of the linked task, so a node keeps its own value in the sum. Leaving the own value out is the second report's variant, and the editorial shows the one-line change. Treating that report's tree as a BST follows the linked task and is our reading. Our choices: 1 to 500 nodes, different values from -10^4 to 10^4, and new examples.

Our version is about 80% the same as the reported questions.

You are given the root of a binary search tree whose values are all different. Change the value of every node to its original value plus the sum of all values in the tree that are larger than it.

Keep the shape of the tree (only the values change) and return its root. The largest value stays the same, and the smallest value becomes the sum of the whole tree.

Function

greaterSumTree(root: TreeNode) → TreeNode

Examples

Example 1

root = [6,3,10,1,4,null,12]return = [28,35,22,36,32,null,12]
root
63141012
Removed
→
return
283536322212
Moved or new

The values in increasing order are 1, 3, 4, 6, 10, 12. Going from the largest down: 12 stays 12; 10 becomes 10 + 12 = 22; 6 becomes 6 + 22 = 28; 4 becomes 32; 3 becomes 35; 1 becomes 36. The shape does not change, so read level by level the answer is [28, 35, 22, 36, 32, null, 12].

Example 2

root = [0,-5,5]return = [5,0,5]
root
0-55
Removed
→
return
505
Moved or new

5 is the largest, so it stays 5. 0 becomes 0 + 5 = 5. -5 becomes -5 + 0 + 5 = 0.

Example 3

root = [7]return = [7]
root
7
→
return
7

A single node has no larger value, so it keeps its value.

Constraints

  • The tree has 1 to 500 nodes.
  • -10^4 <= Node.val <= 10^4, and all values are different.
  • The tree is a valid binary search tree: every value in a node's left subtree is smaller than the node's value, and every value in its right subtree is larger.

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Inorder Predecessor in a BSTNutanix · PHONE SCREENNutanix interview questions
  • Shortest Path Between BST NodesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Validate Binary Search TreeTokopedia · ONSITE INTERVIEWTokopedia interview questions
  • Check the Order of a Binary Search TreeCapital One · ONSITE INTERVIEWCapital One interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Validate Binary Search TreeKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions

Interview reports that mention this question

  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe CS1 Interviews: 14 Experiences (Part 4 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public TreeNode greaterSumTree(TreeNode root) {
        // Write your code here.
    }
}
Checking account…