FastPrepSum of Left Leaves
Problems/Sum of Left Leaves

Sum of Left Leaves

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2023 report from an Expedia software development engineer intern loop in India lists the sum of the left leaves of a binary tree among its interview questions. The author does not say which interview asked it.

The report names the task only. Here a left leaf is a node with no children that is the left child of its parent, so a tree with one node has none and the answer is 0. The tree comes as the usual level-order input. We chose the limits of up to 10^4 nodes with values from -1000 to 1000.

Our version is about 90% the same as the reported question.

You are given the root of a binary tree. A leaf is a node with no children. A left leaf is a leaf that is the left child of its parent.

Return the sum of the values of all left leaves. If there are none, return 0.

The root has no parent, so it is never a left leaf, even when it has no children.

Function

sumOfLeftLeaves(root: TreeNode) → int

Examples

Example 1

root = [5,3,8,1,4,7]return = 8
root
531487

The leaves are 1, 4 and 7. Leaf 1 is the left child of 3 and leaf 7 is the left child of 8, so both count. Leaf 4 is a right child, so it does not. The answer is 1 + 7 = 8.

Example 2

root = [2,null,6,4,null,-3]return = -3
root
264-3

Node 4 is a left child, but it has a child of its own, so it is not a leaf. Its left child -3 is a leaf, and it is the only left leaf. The answer is -3.

Example 3

root = [9]return = 0
root
9

The root is a leaf, but it is nobody's child, so it is not a left leaf. There are no left leaves, and the sum is 0.

Constraints

  • The number of nodes in the tree is in the range [1, 10^4].
  • -1000 <= Node.val <= 1000

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Symmetric Binary TreeFigma · ONSITE INTERVIEWFigma interview questions
  • Tree Level with the Most NodesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Mirror a Binary TreeAMD · ONSITE INTERVIEWAMD interview questions
  • Find a Node’s Level in an N-ary TreeMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Symmetric Binary TreeCapital One · ONSITE INTERVIEWCapital One interview questions
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Vertical Order Traversal of a Binary TreeTokopedia · ONSITE INTERVIEWTokopedia interview questions

Interview reports that mention this question

  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia 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 sumOfLeftLeaves(TreeNode root) {
        // Write your code here.
    }
}
Checking account…