Welcome to the Python screen.
The question is on your right: Serialize and Deserialize Binary Tree. Read through the requirements first.
Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?
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):