Thumbtack Interview Question: Serialize and deserialize a b... | Glassdoor

Interview Question

Software Engineer Interview

Serialize and deserialize a binary tree.


Interview Answer

1 Answer


Serialize: Recursively build a string, and be sure to handle the case where a child is null.

Deserialize: Recursively parse the input string, and construct the Node/Tree object. I used a regular expression to achieve this, however, there was a kink in my regex about 10 minutes prior to the end of the interview. At which point, I was told by the interviewer that it was impossible to parse the string using regex. After which, I detailed how I would go about parsing the string manually and the interview concluded. Approximately 5 minutes after the interview, I was able to correct my regular expression to parse JSON.

Interview Candidate on May 26, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.