Tap here to switch tabs
Problem
Submissions

Problem: Smallest String Starting From Leaf

Smallest String Starting From Leaf asks you to find the lexicographically smallest string formed by reading letters from any leaf up to the root of a binary tree.

Statement

Given the root of a binary tree where each node has an integer value from 00 to 2525 representing the lowercase letters 'a' through 'z' (with 00 corresponding to 'a', 11 to 'b', and so on up to 2525 for 'z'), return the lexicographically smallest string that starts at a leaf node and ends at the root.

A leaf is a node with no children.

Note: If one string is a prefix of another, the shorter string is considered lexicographically smaller (for instance, "ab" comes before "aba").

Constraints:

  • The number of nodes in the tree is in the range [1,8500][1, 8500].

  • 0≤0 \leq Node.val ≤25\leq 25

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Smallest String Starting From Leaf

Smallest String Starting From Leaf asks you to find the lexicographically smallest string formed by reading letters from any leaf up to the root of a binary tree.

Statement

Given the root of a binary tree where each node has an integer value from 00 to 2525 representing the lowercase letters 'a' through 'z' (with 00 corresponding to 'a', 11 to 'b', and so on up to 2525 for 'z'), return the lexicographically smallest string that starts at a leaf node and ends at the root.

A leaf is a node with no children.

Note: If one string is a prefix of another, the shorter string is considered lexicographically smaller (for instance, "ab" comes before "aba").

Constraints:

  • The number of nodes in the tree is in the range [1,8500][1, 8500].

  • 0≤0 \leq Node.val ≤25\leq 25