Subtree of Another Tree, two ways

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Cost

Work done so far, and how the two solutions compare

root and subRoot

A subtree is a node plus all its descendants

Keyboard: ← → step, Space play or pause. Enter the tree in level order with null for missing children, as LeetCode does (root up to 9 nodes, subRoot up to 5, values −99 to 99, so the serialized strings stay readable). In the DFS view a dashed ∅ marks a missing child being compared.