Same Tree

Trees · DFS · Compare matching recursive structure · Easy · about 18 min

Why it matters

Recursive tree problems become manageable when base cases are written first.

How it connects

Depth asked one tree a question. This asks two matching nodes the same question together.

Try first

Which three situations should stop the recursion immediately?

Interview cue

I compare identical structure recursively, visiting each paired node once.