Loading problem…
Implement two functions:
serialize - Convert a binary tree to a stringdeserialize - Convert a string back to a binary treeGiven a binary tree node structure, serialize it to a string format and then deserialize it back to reconstruct the original tree.
// Tree structure:
// 1
// / \
// 2 3
// / \
// 4 5
const root = new TreeNode(1);
root.left = new TreeNode(2);
root.right = new TreeNode(3);
root.right.left = new TreeNode(4);
root.right.right = new TreeNode(5);
const serialized = serialize(root);
// "1,2,null,null,3,4,null,null,5,null,null"
const deserialized = deserialize(serialized);
// Reconstructs the original treeThis problem models real data serialization scenarios: