Implement two functions that turn a binary tree into a string and back:
serialize(root) — preorder (node, left, right), comma-separated, writing # for a missing child.
deserialize(data) — rebuild the exact same tree from that string.solve(levelOrder) is already wired: it builds the tree, serializes it, then
deserializes the string and returns [data, roundTrip], where roundTrip is the
rebuilt tree in level-order form. You only fill in the two functions.
Examples
solve([1, 2, 3, null, null, 4, 5])
→ ["1,2,#,#,3,4,#,#,5,#,#", [1, 2, 3, null, null, 4, 5]]
solve([1, null, 2]) → ["1,#,2,#,#", [1, null, 2]]
solve([]) → ["#", []]Values may be negative, so parse tokens with Number()/int(), not by character.
Sample tests