Problem. Given the roots of two binary trees p and q, return whether they are the same: identical shape and
equal values at every corresponding node.
p: 1 q: 1 → True
/ \ / \
2 3 2 3
p: 1 q: 1 → False (2 is a left child in p, a right child in q)
/ \
2 2
Comparing two trees in lockstep is a pattern you'll reuse: symmetry (lesson 10.3), subtree matching (Change A), merging trees, and diffing tree-shaped data.
ML context. "Are these two structures identical?" comes up constantly: has a model's module tree changed between checkpoints, are two experiment configs the same, can a cached compilation of a computation graph be reused for this graph? At scale you don't compare structures pairwise; you hash them so equal structures get equal fingerprints (Changes A to C).