Sum of Left Leaves
EasyTreesdfs
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given the root of a binary tree, return the sum of the values of all **left leaves**.
A left leaf is a node with no children that is the left child of its parent. The root has no parent, so a single-node tree has no left leaves and the answer is 0. Right leaves are ignored no matter how deep they are.
Examples
Input: root = [3,9,20,null,null,15,7]
Output: 24
9 and 15 are left leaves; 7 is a right leaf. 9 + 15 = 24.
Input: root = [1]
Output: 0
The lone root is not a left child.
Constraints
- 1 <= number of nodes <= 1000
- -1000 <= Node.val <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.