Phase 1: Two trees with the same values. Are they the same tree?

These two trees look almost identical. Same root, same left child, same right child. But one detail differs deep in the structure. The question is whether they count as the “same tree.” Look carefully before you decide.

Same Tree (LC 100): given two binary trees, return true if they are structurally identical AND value-identical at every position. Subtree of Another Tree (LC 572): given a tree and a candidate, return true if the candidate appears anywhere as a structural match inside the larger tree.

FIG. 1 — TWO TREES — SPOT THE DIFFERENCE
Tree A
Tree B
— They share the same top two levels. Look deeper. —

“Same” means identical at every depth. Two trees can share the same root, same children, and still differ at a grandchild. Every position must match. But how do you check them all systematically? And for Subtree, a root-level check only catches one position — a real match could hide at any depth.

FIG. 2 — PREDICT BEFORE YOU PROCEED

A lockstep comparison visits paired positions simultaneously — root with root, left child with left child. At which depth will the comparison first return false?