Facebook | Phone screen | Serialize and deserialize binary tree
Anonymous User
1024

Status: New Grad

Given the root to a binary tree, serialize to a List<Integer and deserialize back to the original tree.

Easy question that can run in O(N) time/space. I mentioned using a Deque to build back the tree for easier implementation at the cost of additional O(N) time/space but I went for the optimized method using the original List. I missed a bug that should've kept track of a global index for the List during recursion and I could not fix in time. It was an easy one line add of code though.

Overall very pleasant experience and I hope I somehow advance despite the small bug.

Comments (2)