In a Meta-style systems setting such as caching tree-structured ranking features for Facebook Feed, you may need to convert a binary tree into a compact string and later rebuild the exact same tree. Implement both serialization and deserialization.
Given the root of a binary tree, write two functions:
serialize(root) that converts the tree into a string.deserialize(data) that reconstructs the original binary tree from that string.Your encoding must preserve both node values and structure, including missing children.
serialize: root, the root node of a binary tree or nullserialize: a string representation of the treedeserialize: data, a string produced by serializedeserialize: the reconstructed root node or nullYou may choose any deterministic format, but deserialize(serialize(root)) must produce a tree identical to the original.
Example 1
root = [1,2,3,null,null,4,5]"1,2,#,#,3,4,#,#,5,#,#"# markers preserves missing children.Example 2
root = []"#"[0, 10^4]-1000 <= Node.val <= 1000