 All Problems
Serialize and Deserialize Binary Tree
hard
design
tree
bfs
dfs
facebook
amazon
google
microsoft

Design an algorithm to serialize and deserialize a binary tree.

  • String serialize(TreeNode root) — encodes the tree to a string.
  • TreeNode deserialize(String data) — decodes the string back to the tree.

There is no restriction on your serialization/deserialization algorithm.

Example:

Input: root = [1,2,3,null,null,4,5]
Output: [1,2,3,null,null,4,5]
Run to check your code against the sample cases, or submit to run every case