#C4783. Longest Root-to-Leaf String

    ID: 48359 Type: Default 1000ms 256MiB

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 c1,c2,,ckc_1, c_2, \ldots, c_k, then the corresponding string is S=c1c2ckS=c_1c_2\ldots c_k. Your goal is to compute the maximum SS 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