Grokking Tree Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

Subtree of Another Tree (easy)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given the roots of two binary trees, root and subRoot, return true if subRoot is a subtree of root. Otherwise, return false.

A subtree of a binary tree is a part of the tree that includes a node and all of its descendants. The tree tree could also be considered as a subtree of itself.

Examples

Example 1

  • Input: root = [3, 6, 5, 1, 4], subRoot = [6, 1, 4]
  • Expected Output: true
  • Explanation: The subtree starting at node 6 in root has the same structure and values as subRoot.

Example 2

  • Input: root =

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible