Symmetric Tree

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Symmetric Tree

Approach

Compare two opposite branches recursively and ensure each pair of nodes mirrors value and structure.

Complexity Analysis

Time
O(n) where n is node count
Space
O(h) where h is tree height

Pattern

Tree Symmetry Check

Why It Works

A tree is symmetric only if left subtree and right subtree are mirror images at every level.

Updated Feb 2026