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

0% completed

Vote For New Content
Symmetric Tree (easy)
On this page

Problem Statement

Examples

Try it yourself

Problem Statement

Given the root of a binary tree, return true if the tree is symmetric, meaning it is a mirror image of itself. Otherwise, return false.

A tree is considered symmetric if the left subtree is a mirror reflection of the right subtree.

Examples

Example 1:

  • Input: root = [1,5,5,3,4,4,3]
Image
  • Expected Output: true
  • Justification: The tree is symmetric because the left subtree mirrors the right subtree at every level.

Example 2:

  • Input: root = [1,5,5,null,3,null,3]
Image
  • Expected Output: false
  • Justification: The tree is not symmetric because the left and right subtrees do not match in structure or values.

Example 3:

  • Input: root = [1,2,2,null,3,3,null]
Image
  • Expected Output: true
  • Justification: The tree is symmetric because the left and right subtrees are mirror images in terms of structure and values.

Constraints:

  • The number of nodes in the tree is in the range [1, 1000].
  • -100 <= Node.val <= 100

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Examples

Try it yourself