#C3986. Row-Wise Maximum in a Binary Tree

    ID: 47473 Type: Default 1000ms 256MiB

Row-Wise Maximum in a Binary Tree

Row-Wise Maximum in a Binary Tree

You are given a binary tree in level order, where missing nodes are represented by the string null. Your task is to compute the largest value in each row (i.e., each level) of the tree and print them in order from the root level to the last level.

The input is provided as a single line of space-separated tokens representing the tree in level order. For example, the tree

[ 1 /
3 2 / \ \ 5 3 9 ]

will be given as:

1 3 2 5 3 null 9

The output should be the maximum value on each level printed as space-separated integers.

If the tree is empty (i.e. the input is null or empty), output nothing.

inputFormat

Standard input (stdin) contains a single line of space-separated tokens representing the tree in level order. Each token is either an integer or the string null indicating a missing node.

outputFormat

Print a single line to standard output (stdout) containing the maximum value for each level of the tree, separated by a single space. If the tree is empty, print nothing.## sample

1 3 2 5 3 null 9
1 3 9