Serialise and Deserialise a Binary Tree

hard
Unit 23 · Trees & Graphs0/0 to milestone

Design serialize(root) -> str and deserialize(s) -> root so that any binary tree (with integer values, possibly negative or repeated) round-trips exactly. Use a preorder walk writing values separated by commas and # for missing children.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Serialise and Deserialise a Binary Tree · TechGradify