#C11513. Reverse Level Order Traversal of Binary Tree

    ID: 40838 Type: Default 1000ms 256MiB

Reverse Level Order Traversal of Binary Tree

Reverse Level Order Traversal of Binary Tree

Given a binary tree represented in level order by a list of node values (with the string null representing missing nodes), your task is to perform a reverse level order traversal of the binary tree. In reverse level order traversal, the nodes are traversed level by level from bottom to top, and within each level they are traversed from left to right.

Input Format: The input is provided as a single line from standard input containing node values separated by spaces. The value null represents a missing node. If the input is empty, consider the tree as empty.

Output Format: Output the result as a list of lists where each inner list contains the node values at that level, starting from the bottom-most level. The output should be printed to standard output.

Note: All formulas (if any) are represented in LaTeX format. In this problem, the primary challenge is correct tree construction and traversal.

inputFormat

The input consists of a single line read from standard input. This line contains the values of the tree nodes in level order separated by spaces. Use the string null (case-sensitive) to indicate a missing node. For example:

3 9 20 null null 15 7

outputFormat

The output should be printed on standard output as a Python-style list of lists which represents the reverse level order traversal of the binary tree. For example, the output for the above input would be:

[[15, 7], [9, 20], [3]]
## sample
3 9 20 null null 15 7
[[15, 7], [9, 20], [3]]