Build strings from each leaf to the root and return the lexicographically smallest one.
Given the root of a binary tree where each node contains a value from 0 to 25, treat the value as a lowercase letter with , , and so on.
For every leaf node, form a string by reading letters from that leaf up to the root. Among all such strings, return the one that is lexicographically smallest.
A leaf is a node with no children.
Example 1
Input
root = [0,1,2,3,4,3,4]
Output
dba
Explanation
The leaf-to-root strings are "dba", "eba", "dca", and "eca". The smallest lexicographically is "dba".
Example 2
Input
root = [25,1,3,1,3,0,2]
Output
adz
Explanation
The leaf-to-root strings include "adz", "bzz", and others. The smallest lexicographically is "adz".
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.