Back to Practice Dashboard
DSA SectionMedium

Symmetric Tree

Learn how to solve the 'Symmetric Tree' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Medium

Write a function is_symmetric(tree_arr) that takes an array representation of a binary tree tree_arr and checks if the tree is symmetric (a mirror of itself around the center, matching both structure and values).

Constraints
  • 0 <= len(tree_arr) <= 1000

Examples

Example 1
Input
tree_arr = [1, 2, 2, 3, 4, 4, 3]
Output
True
Explanation

The tree is symmetric in both shape and node values.

Example 2
Input
tree_arr = [1, 2, 2, None, 3, None, 3]
Output
False
Explanation

Left child 2 has right child 3, right child 2 has right child 3. Values match but structures are not mirrors.

Need a Hint?
Perform a recursive tree traversal (DFS) or level-order traversal (BFS) using a queue/stack.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor