Skip to content
C

Serialize and Deserialize Binary Tree

Hardjavapythonccppjavascript

Build a binary tree from its level-order description, then serialize it back to a canonical level-order form: perform a breadth-first walk emitting each node's value, and null for every missing child of a real node. Trailing null tokens are removed.

Input Format

The first line contains an integer M, the number of level-order tokens. The second line contains M space-separated tokens (integers or null).

Output Format

Print the canonical serialization on one line, tokens separated by single spaces. Print an empty line for an empty tree.

Input (stdin)

Output

Run your code to see output here...