Serialize and Deserialize Binary Tree Problem

Serialize and Deserialize Binary Tree Problem — ExecCode Hard DSA Practice

Solve the Serialize and Deserialize Binary Tree problem on ExecCode. Free online hard DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Design an algorithm to serialize and deserialize a binary tree. Serialization is converting a tree to a string. Deserialization is converting the string back to a tree.

Examples

Input root = [1, 2, 3, null, null, 4, 5]; Output "1,2,3,null,null,4,5,null,null,null,null". Input root = [1]; Output "1,null,null". Input root = [1, 2]; Output "1,2,null,null,null"

Constraints

The number of nodes in the tree is in the range [0, 10^4]. -1000 <= Node.val <= 1000

Practice Serialize and Deserialize Binary Tree free on ExecCode. Browse DSA problems, topic map, and placement guides.