15% off all plans & roadmaps Use code
See plansLeetCode 988 · Solution & editorial
You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'.
Smallest String Starting From Leaf is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Preorder Traversal subpattern. The pattern covers preorder, inorder, level order traversal, LCA, and serialization
Master preorder traversal for tree construction, inversion, and path problems. Visit root before children.
The reference solution runs in O(n + l * h) time and O(h) space.
Smallest String Starting From Leaf has been reported in interviews at Google.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Smallest String Starting From Leaf is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Preorder Traversal subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.