Serialize and Deserialize Binary Tree

Hard Solved

Description

Design an algorithm to serialize and deserialize a binary tree.

Serialization is the process of converting a tree into a string. Deserialization is the reverse process.

Input format / Clarification:

  • Line 1: Binary tree in level-order JSON array

Examples

Input:

[1,2,3,null,null,4,5]

Output: [1,2,3,null,null,4,5]

Input:

[]

Output: []

Note:

Your program must print the deserialized tree again as a level-order JSON array.

No submissions yet.

Discuss BFS vs DFS serialization, null handling, and tree reconstruction.

Test Cases