Skip to content
CampusEduX

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.

Related Problems

  • Maximum Path Sum in Binary Tree
    Hard · java, python, c, cpp, javascript
    Solve Problem
  • Boundary Traversal
    Hard · java, python, c, cpp, javascript
    Solve Problem
  • Vertical Order Traversal
    Hard · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...