Check Reflected Binary-Tree Structure and Values

Quick Overview

Check binary-tree mirror symmetry in both structure and values, with recursive and iterative approaches.

Check Reflected Binary-Tree Structure and Values

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Determine whether a binary tree is symmetric about its root: its left and right sides must be mirror images with equal values in corresponding reflected positions. Both shape and values matter. Use the supplied `TreeNode` fields `val`, `left`, and `right`: ```cpp bool isSymmetric(TreeNode* root); ``` Level-order examples use `null` for missing children; the actual argument is a node pointer. ### Examples ```text Input: root = [5,2,2,1,4,4,1] Output: true ``` ```text Input: root = [6,3,3,null,2,null,2] Output: false ``` The two nodes valued 2 both occupy right-child positions, rather than reflected positions. ### Constraints - The tree contains between 1 and 1000 nodes. - Node values lie between -100 and 100, inclusive. ### Source follow-up Consider both recursive and iterative solutions.

Overview: Check binary-tree mirror symmetry in both structure and values, with recursive and iterative approaches.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Determine whether a binary tree is symmetric about its root: its left and right sides must be mirror images with equal values in corresponding reflected positions. Both shape and values matter.

Use the supplied TreeNode fields val, left, and right:

bool isSymmetric(TreeNode* root);

Level-order examples use null for missing children; the actual argument is a node pointer.

Examples

Input: root = [5,2,2,1,4,4,1]
Output: true
Input: root = [6,3,3,null,2,null,2]
Output: false

The two nodes valued 2 both occupy right-child positions, rather than reflected positions.

Constraints

  • The tree contains between 1 and 1000 nodes.
  • Node values lie between -100 and 100, inclusive.

Source follow-up

Consider both recursive and iterative solutions.