Description
Design algorithms to serialize an N-ary tree into a string and deserialize the string back to the original tree structure.
Examples
Input:
root = [1,null,3,2,4,null,5,6]Output:
[1,null,3,2,4,null,5,6]Explanation:
N-ary tree serialization.
Input:
root = [1,null,2,3,null,4,null,5,6,7]Output:
[1,null,2,3,null,4,null,5,6,7]Explanation:
This N-ary tree has varying children per node. Serialization preserves the structure using null markers.
Input:
root = []Output:
[]Explanation:
An empty N-ary tree serializes to an empty array.
Constraints
- •
0 ≤ nodes ≤ 10⁴