Where it runs
1. The problem
You have two versions of the same thing. For example, the config you saved and the config the server is running with right now. Or the last render of the interface and the new one. The question: are they exactly the same, with the same shape and the same values everywhere? If they are, the framework can skip redrawing the screen, and a backup tool doesn't upload the file again.
You can ask the same tree another question: is it symmetric, does its left side match the mirror image of its right side? And a third: is there a path from the root to a leaf whose values add up to a given number (a budget, a score threshold)?
In the last lessons the recursion walked one tree. Here it walks two places at once, in step: two trees, or the two halves of one tree.
This step is part of the paid track
The first 33 steps are open to everyone: lesson, exercise and tests. This one opens with full access. Start with a free account and the free steps.
Create a free accountSee what is includedOn LeetCode
Problems that compare two trees or check a property along root to leaf paths. Recurse on matching pairs of nodes, or carry a running value down the tree.
The lesson's isSameTree under the same name.
The lesson's isSymmetric, comparing left with right and right with left.
The lesson's hasPathSum, subtracting each value from the target on the way down.
Run isSameTree from every node of the big tree.
hasPathSum that also keeps the path, adding a node on the way down and removing it on the way back, as in backtracking.