We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
An easy trees problem, graded against 7 test cases (4 of them hidden).
Recursive traversal of binary trees and BSTs - depth, validation, and path problems.
Reach for it when you see: A TreeNode input, or anything about depth, ancestry, or in-order ordering.
More Treesproblems →Traverse the tree (DFS or BFS). For each node, look at its left child: if that child exists and has no children of its own, it is a left leaf - add its value. Right subtrees are still traversed, because they may contain left leaves deeper down.
With the level-order array representation, node `i`'s children live at `2i+1` and `2i+2`, so leaf-checking is two index lookups.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.