Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

data =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use BFS order with null markers to preserve structure.

Approach

  • Serialize: BFS; append val for nodes and # for nulls.
  • Deserialize: Rebuild in BFS order: pop parent, assign left and right from the next tokens. Trim trailing # during serialization to reduce size.

Why it works

BFS with null markers uniquely identifies the original tree’s structure and values.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Use BFS order with null markers to preserve structure.

Approach

  • Serialize: BFS; append val for nodes and # for nulls.
  • Deserialize: Rebuild in BFS order: pop parent, assign left and right from the next tokens. Trim trailing # during serialization to reduce size.

Why it works

BFS with null markers uniquely identifies the original tree’s structure and values.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)