Serialize and Deserialize Binary Tree
HardProblem Description
Design an algorithm to serialize and deserialize a binary tree.
Implement:
serialize(root)that converts a tree to a string.deserialize(data)that converts the string back to the original tree.
In this live problem, your solution is validated using a round-trip check:
- Serialize the input tree.
- Deserialize it.
- Return the rebuilt tree in level-order list format.
Examples
Example 1:
Input: root = [1,2,3,null,null,4,5]
Output: [1,2,3,null,null,4,5]
Example 2:
Input: root = []
Output: []
Constraints
- The number of nodes in the tree is in the range
[0, 10^4]. -1000 <= Node.val <= 1000
Hint
Preorder traversal with explicit null markers is a common reliable approach.
Solution
Test Results
Run tests to see the overall score, band, and section breakdown.
Public Tests
Detailed feedback for visible cases.
Public test details will appear here after you run your solution.
Hidden Tests
Summary only, with no hidden inputs or outputs.
Performance
Execution timing and pass/fail status.
No performance results yet.
AI Interviewer
I'll review your code once you submit it. I can also give you hints if you get stuck!