Question bank › Trees
Dsa Trees Hard

Tree Serialization and Deserialization

Implement methods to serialize and deserialize a binary tree. Serialization is the process of converting a tree to a string, and deserialization is the reverse process. Input: - The first line contains an integer n, the number of nodes in the binary tree. - The next n lines contain node values in a level order traversal (use -1 for null nodes). Output: - Output the serialized string and then deserialize it back and print the confirmation that the structure is preserved. Example: Input: 5 1 2 3 -1 -1 -1 -1 Output: 1,2,3,null,null,null,null Successfully deserialized back to original structure.

Key concepts

treesserializationdeserialization

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.