Back to problems

Subtree of Another Tree

Algorithm · Medium

You are given two binary trees through their root references root and subRoot. Your task is to decide whether the tree rooted at root contains a subtree that perfectly matches the tree rooted at subRoot in both structure and node values. If a match is found, return true; otherwise return false. A subtree of a binary tree is defined by taking any node and all of its descendants. That is, the chosen node together with its complete branch down to every leaf must be considered;…

Checking your access…