#K77392. Largest Value in Each Tree Row

    ID: 34854 Type: Default 1000ms 256MiB

Largest Value in Each Tree Row

Largest Value in Each Tree Row

Given a binary tree represented in level order as a comma‐separated string (with null for missing nodes), find the largest value in each row of the tree.

Let the binary tree be denoted as \(T\). You are required to compute for every level \(i\) of \(T\), the maximum element \(m_i\). In other words, if the \(i\)th level contains nodes \(\{a_1, a_2, \dots, a_k\}\), then compute:

[ m_i = \max{a_1, a_2, \dots, a_k} ]

Output the sequence \(m_0, m_1, \dots\) (from the root level 0 to the last level) as space separated values in one line.

inputFormat

The input consists of a single line containing a comma-separated list of values. Each value is either an integer or the string null representing a missing node. This list represents a binary tree in level order. For example: 1,3,2,5,3,null,9 corresponds to the tree with root 1, its left child 3, its right child 2, and so on.

outputFormat

Print the largest value in each row (level) of the binary tree as space separated integers in one line. If the tree is empty, print an empty line.

## sample
1,3,2,5,3,null,9
1 3 9