Dashboard
LC #297

Serialize and Deserialize Binary Tree

Pattern · ?MetaGoogleAmazonMicrosoftBloomberg

Problem

Design an algorithm to serialize a binary tree to a string and deserialize it back to the original tree.

Constraints

  • 0 ≤ number of nodes ≤ 10⁴
  • -1000 ≤ node.val ≤ 1000

Example

Input
root = [1, 2, 3, null, null, 4, 5]
Output
"1,2,3,null,null,4,5" → reconstructed tree
Why
BFS level-order encoding with null markers allows exact reconstruction

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗