#K14821. Largest Values in Each Tree Row

    ID: 24220 Type: Default 1000ms 256MiB

Largest Values in Each Tree Row

Largest Values in Each Tree Row

Given the root of a binary tree, find the largest value in each row. The binary tree is provided in level-order format where null represents a missing node. For each level of the tree, compute the maximum value among all the nodes in that row. Formally, if the largest values are \(a_0, a_1, \ldots, a_{k-1}\), then the answer should be output as:

[a0,a1,,ak1][a_0, a_1, \ldots, a_{k-1}]

Print the output as space-separated integers.

inputFormat

A single line of input containing space-separated tokens representing the binary tree in level-order. Use the literal string "null" to denote missing nodes.

outputFormat

Output a single line of space-separated integers representing the largest value in each row of the binary tree.## sample

1 3 2 5 3 null 9
1 3 9