Smallest String Starting From Leaf
You are given the root of a binary tree. Every node holds a number 0 to 25, standing for the letters a to z (0 is a, 25 is z). Each path from a leaf up to the root spells a word (the leaf's letter first, the root's letter last). Return the alphabetically smallest of these words. A shorter word that is the beginning of a longer one counts as smaller. The tree has at least one node.
Trees appear in the tests in level order, with null for a missing child, like [3,9,20,null,null,15,7]. Each node is a TreeNode with .val, .left and .right; the class is already defined for you.
Example 1
Leaf words: "dba", "eba", "dca", "eca". The smallest is "dba".
Constraints
1 <= number of nodes <= 1000 <= node.val <= 25
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.