#K47172. Binary Tree Right-to-Left Level Order Traversal

    ID: 28140 Type: Default 1000ms 256MiB

Binary Tree Right-to-Left Level Order Traversal

Binary Tree Right-to-Left Level Order Traversal

Given a binary tree, perform a level order traversal where each level is traversed from right to left. You are provided with the tree as a level order sequence (with the string null representing a missing node). First, reconstruct the binary tree from the input, and then return its level order traversal, with each level processed from right to left.

The algorithm should run in \(O(n)\) time, where \(n\) is the number of nodes in the tree.

inputFormat

Input is read from standard input as a single line containing space-separated tokens. Each token represents a node value in level order; use the string "null" to indicate the absence of a node.

outputFormat

Output the right-to-left level order traversal as a list of lists in Python list format. For example: [[3], [20, 9], [7, 15]]## sample

1
[[1]]