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.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.