FastPrepSum Root-to-Leaf Binary Numbers
Problems/Sum Root-to-Leaf Binary Numbers

Sum Root-to-Leaf Binary Numbers

Oracle logoOracle● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Oracle phone screen. The report names the task of adding up binary numbers from root to leaf. Node values are binary digits, and each path from the root to a leaf is read as one binary number. Those rules fix the whole task.

You are given the root of a binary tree whose node values are 0 or 1.

Each root-to-leaf path represents a binary number, with the root as the leftmost, most significant bit. Return the sum of all represented numbers.

A leaf is a node with no children.

Function

sumRootToLeaf(root: TreeNode) → int

Examples

Example 1

root = [1,0,1,0,1,0,1]return = 22
root
1001101

The four paths represent 100, 101, 110, and 111, which sum to 22.

Example 2

root = [0]return = 0
root
0

The only path represents zero.

Example 3

root = [1]return = 1
root
1

The only path represents one.

Constraints

  • The tree contains between 1 and 1000 nodes.
  • node.val is 0 or 1.
  • The sum fits a signed 32-bit integer.

More Oracle Phone Screen questions

  • Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · Seen Oct 2026
  • Shortest Window by Distinct-Value SumPHONE SCREEN · Seen Oct 2026
  • Detect a Cycle in a Directed GraphPHONE SCREEN · Seen Oct 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Remove Adjacent Duplicates in String IIPHONE SCREEN · Seen Oct 2026
  • Longest All-Present Attendance StreakPHONE SCREEN · Seen Oct 2026
  • Next PermutationPHONE SCREEN · Seen Sep 2026
  • Valid ParenthesesPHONE SCREEN · Seen Sep 2026
  • Valid Parenthesis StringPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Merge Two Binary TreesSnowflake · PHONE SCREENSnowflake interview questions
  • Sum All Values in a Binary TreeDuolingo · PHONE SCREENDuolingo 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

Oracle interview experiences

  • Oracle SWE Onsite Interview Experience: 1 Experience
All Oracle interview questionsSee Oracle 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 int sumRootToLeaf(TreeNode root) {
        // Write your code here.
    }

}
Checking account…