Pattern Recognition Drill
Medium Advanced Trees
The Problem
Serialize a binary tree to a string and reconstruct it.
What approach would you use?
Think about it before scrolling down.
Serialize: preorder with '#' for nulls. Deserialize: read values in order, recurse. O(n).
Level-order serialization with null markers also works. Same O(n).
Common Trap
Need null markers to distinguish tree shapes. Without them, different trees can have same traversal.