Your question is Serialize and Deserialize Binary Tree. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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.
def serialize_deserialize_tree(root):