Subtree of Another Tree Problem

Subtree of Another Tree Problem — ExecCode Medium DSA Practice

Solve the Subtree of Another Tree problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

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.

Examples

Input root = [3, 4, 5, 1, 2], subRoot = [4, 1, 2]; Output true

Constraints

1 ≤ nodes ≤ 2000 -10^4 ≤ Node.val ≤ 10^4

Practice Subtree of Another Tree free on ExecCode. Browse DSA problems, topic map, and placement guides.