#K93292. Largest Value in Each Tree Level
Largest Value in Each Tree Level
Largest Value in Each Tree Level
You are given a binary tree and your task is to find the largest value on each level of the tree. The binary tree is provided in a level-order traversal format where the keyword null
represents a missing node.
For example, given the tree represented as 1 3 2 5 3 9 6
, its structure is
(\begin{array}{c}\ \ 1 \ 3 \quad 2 \ 5\ 3\ 9\ 6 \end{array}) and the largest values in each level are: 1 (level 1), 3 (level 2), and 9 (level 3).
inputFormat
The input is a single line containing the level-order traversal of the binary tree. The node values are separated by spaces. Use the keyword null
(case-sensitive) to represent missing nodes. You can assume that the input represents a valid binary tree.
outputFormat
Output a single line with the largest value from each level of the tree, in order from the root level to the deepest level. The values should be separated by a single space.## sample
1
1