dsa1 min read
Find Duplicate Subtrees — Serialize + HashMap
Find all duplicate subtrees by serializing each subtree and tracking serialization counts in a hash map.
Read →
webcoderspeed.com
3 articles
Find all duplicate subtrees by serializing each subtree and tracking serialization counts in a hash map.
Design an encode/decode scheme for a list of strings. Length-prefix encoding (4-byte header per string) is collision-proof unlike delimiter-based approaches.
Serialize a binary tree to a string and deserialize it back. Meta loves this problem for testing tree traversal and string parsing. Both BFS and preorder DFS approaches shown.