Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Smallest String Starting From Leaf

XPChallenge Points: 20
levelLevel: Medium

Each node stores a value in [0..25] mapping to letters 'a'..'z'.
For every leaf→root path, form a string by converting values to letters and reading from the leaf up to the root. Return the lexicographically smallest such string.

Example 1:

Input: root = [0,1,2,3,4,3,4]

Output: "dba"

Example 2:

Input: root = [25,1,3,1,3,0,2]

Output: "adz"

Example 3:

Input: root = [2,2,1,null,1,0,null,0]

Output: "abc"

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result