Serialize and Deserialize Binary Tree
Hard
Trees
BFS
DFS
Design an algorithm to serialize and deserialize a binary tree.
Input: level-order with null markers
Output: same format after round-trip
Constraints
See problem-specific constraints. Optimized solution required.
Examples
Example 1:
Input: 1 2 3 null null 4 5
Output:
Example 2:
Input: 1 2 3 null null 4 5
Output:
Hints
Consider a bfs approach.
Think about time complexity.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console