FastPrepSum All Values in a Binary Tree
Problems/Sum All Values in a Binary Tree

Sum All Values in a Binary Tree

Duolingo logoDuolingo● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for a recursive sum of every node in a binary tree. We chose how an empty tree works and the number limits. Our version is about 97% the same as the reported question.

Given the root of a binary tree, return the sum of all node values. An empty tree has sum zero.

Function

sumTree(root: TreeNode) → long

Examples

Example 1

root = [1,2,3]return = 6
root
123

The node values sum to 1 + 2 + 3 = 6.

Example 2

root = []return = 0
root
empty

The empty tree has sum zero.

Example 3

root = [-5,2,8]return = 5
root
-528

Negative and positive node values are both included.

Constraints

  • The tree contains between 0 and 100000 nodes.
  • Node values are signed 32-bit integers.
  • The total fits signed 64-bit arithmetic.

More Duolingo Phone Screen questions

  • Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
  • Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
  • Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
  • Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
  • Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
  • Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
  • User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
  • Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
  • Validate a Mahjong Hand PartitionPHONE SCREEN · Seen Nov 2025
  • Directional Tiles: Find a Valid Reconfiguration PathPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Merge Two Binary TreesSnowflake · PHONE SCREENSnowflake interview questions
  • Sum Root-to-Leaf Binary NumbersOracle · PHONE SCREENOracle interview questions
  • Symmetric Binary TreeDocuSign · PHONE SCREENDocuSign interview questions
  • Count One-Valued Regions in a Binary TreeGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Maximum Value in a Binary TreeAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Root-to-Leaf Paths as StringsAdobe · PHONE SCREENAdobe interview questions
  • Left View of a Binary TreeMygate · PHONE SCREENMygate interview questions
  • Binary Tree Preorder TraversalMorgan Stanley · PHONE SCREENMorgan Stanley interview questions
  • Range Sum of BSTMeta · PHONE SCREENMeta interview questions

Duolingo interview experiences

  • Duolingo interviews · November 2026
  • Duolingo SWE Interview Questions: 3 Experiences
All Duolingo interview questionsSee Duolingo 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 long sumTree(TreeNode root) {
        // Write your code here.
    }

}
Checking account…