#K70547. Maximum Performance Score Per Level in a Binary Tree
Maximum Performance Score Per Level in a Binary Tree
Maximum Performance Score Per Level in a Binary Tree
You are given a binary tree where each node contains an integer representing its performance score. Your task is to determine the maximum performance score at each level of the tree. The level of the root node is considered as level 0. This problem is commonly encountered in performance analysis, where identifying optimal metrics at each hierarchical level is essential.
You are required to perform a level-order traversal (BFS) of the binary tree and output the maximum value from each level. The tree will be provided in a serialized format. Use appropriate data structures to efficiently process the tree.
Note: All input is read from standard input (stdin) and the result should be printed to standard output (stdout).
inputFormat
The first line contains an integer n, denoting the number of nodes in the tree. This is followed by n lines, each describing a node in the format:
node_id value left_child_id right_child_id
If a child does not exist, its id will be -1. The node with id 1 is guaranteed to be the root of the tree.
outputFormat
Output a single line containing the maximum performance score at each level of the binary tree, separated by a single space.## sample
6
1 1 2 3
2 3 4 5
3 2 -1 6
4 5 -1 -1
5 3 -1 -1
6 9 -1 -1
1 3 9
</p>