EASYasked at 1 company

Sum of Left Leaves

A easy-tier problem at 62% community acceptance, tagged with Tree, Depth-First Search, Breadth-First Search. Reported in interviews at Grammarly and 0 others.

Founder's read

Sum of Left Leaves shows up in tree interviews, and it's exactly the kind of problem that looks trivial until you get the definition of 'left leaf' wrong on a whiteboard. You need to identify nodes that are both children of a parent and have no children themselves, sitting specifically in the left position. Grammarly has asked this. The acceptance rate sits at 62%, which means a solid chunk of candidates nail it, but the remainder stumble on edge cases or overthink the recursion. This is the problem where a clean DFS pass saves you five minutes of debugging in your assessment.

Companies asking
1
Difficulty
EASY
Acceptance
62%

Companies that ask "Sum of Left Leaves"

If this hits your live OA

Sum of Left Leaves is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The trap: people confuse 'left child' with 'left leaf.' A left leaf must satisfy two conditions: it's the left child of its parent AND it has no children. If you just sum all left children, you'll include internal nodes and fail test cases. The actual solution is straightforward DFS. Traverse the tree, and only when you hit a node that is both a left child and a leaf (no left or right subtree) do you add its value to the sum. The recursion handles the left and right subtrees naturally. This is why it's marked easy. But in a live assessment, if you misread the problem or second-guess yourself on what 'left leaf' means, you'll waste time rewriting. StealthCoder is your safety net if that happens: it surfaces a correct solution in seconds so you move on.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Sum of Left Leaves recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sum of Left Leaves interview FAQ

What's the difference between a left child and a left leaf?+

A left child is any node in the left position. A left leaf is a left child that has no children of its own. You must check both conditions. Many candidates sum all left children and fail hidden test cases because they include nodes with subtrees.

Should I use DFS or BFS for this problem?+

DFS is the cleaner choice and what most solutions use. You recursively visit the left and right subtrees, checking at each step whether the current node is a left leaf. BFS works too but adds unnecessary queue overhead for a problem this straightforward.

How do I know if a node is a left child during recursion?+

You need to pass context down: when you recurse into the left subtree, mark those nodes as left children. On the right subtree, mark them as right children. Then at each node, check if it's marked as left and has no children before adding to the sum.

Is this problem still asked at real companies?+

Yes. Grammarly has reported it. It's a classic tree warm-up question in phone screens and online assessments. It's not as frequent as some other tree problems, but it still appears regularly enough that you should know the pattern.

What's the time and space complexity I should claim?+

Time is O(n) because you visit each node once. Space is O(h) for the recursion stack, where h is the height of the tree. In a balanced tree that's O(log n), but in the worst case it's O(n). Mention both and you're covered.

Want the actual problem statement? View "Sum of Left Leaves" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.