The problem. Design a Codec with serialize(root), which turns a binary search tree into a string, and deserialize(data), which rebuilds exactly the same tree from that string. The string should be as compact as possible.
root = [2, 1, 3] serialize -> "2,1,3" deserialize -> [2, 1, 3]
root = [8, 3, 10, 1, 6, null, 14] serialize -> "8,3,1,6,10,14"
root = [] serialize -> "" deserialize -> []Members only · free account
The rest of this lesson, with 5 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson