Design an algorithm to serialize a binary tree to a string and deserialize it back. The format must capture the structure completely including null nodes.
Preorder traversal with null markers. Serialize: DFS, write value or 'N' for null. Deserialize: read values, recursively build tree.
💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!
s
1,2,N,N,3,4,N,N,5,N,N
serialize(root2) == s
True