Interactive Subtree Algorithm Learning
Problem: Subtree of Another Tree
Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.
A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.
Example 1:
Input: root = [1,2,3,4,5], subRoot = [2,4,5]
Output: true
The subtree with root 2 in the main tree matches the structure and values of subRoot.
Example 2:
Input: root = [1,2,3,4,5,null,null,6], subRoot = [2,4,5]
Output: false
While the subtree with root 2 appears similar, the additional node 6 as a child of node 4 means the structures don't match.
Constraints:
- 0 ≤ The number of nodes in both trees ≤ 100
 - -100 ≤ root.val, subRoot.val ≤ 100
 
Recommended Time & Space Complexity:
You should aim for a solution as good or better than O(m * n) time and O(m + n) space, where n and m are the number of nodes in root and subRoot, respectively.
Hints
Tree Visualization
Main Tree
Subtree
Current Step
Start with isSubtree(root, subRoot) where root is node 1 and subRoot is node 2. We check if the entire trees are identical.