#C4783. Longest Root-to-Leaf String
Longest Root-to-Leaf String
Longest Root-to-Leaf String
You are given a binary tree where each node contains a lowercase letter. Your task is to find the lexicographically largest string formed by concatenating the letters from the root to any leaf. The tree is provided as a level-order traversal where the token 'null' indicates the absence of a node. The string is formed by concatenating the node values along a path from the root to a leaf. If the tree is empty, output an empty string.
The lexicographical order is defined as in standard dictionary order. For example, between the strings "ba" and "bc", the lexicographically larger string is "bc".
Formally, if the path is represented as a sequence of characters , then the corresponding string is . Your goal is to compute the maximum in lexicographical order over all root-to-leaf paths.
inputFormat
Input is given on a single line as space-separated tokens representing the level-order traversal of the binary tree. Each token is either a lowercase letter (representing a node value) or the word 'null' representing an absent child. It is guaranteed that the input represents a valid binary tree.
outputFormat
Output the lexicographically largest string from the root to any leaf. If the tree is empty, output an empty string.## sample
a
a