Trees · Coding problem
Symmetric Tree
A free coding problem from the Binary Tree Mirror & Symmetry skill. Read it here, then solve it in the app in Java or Python.
- Easy
- Coding problem
- Free
- Java and Python
The problem
Does a binary tree look the same in a mirror? Return whether its left half is the mirror image of its right half.
Input format
The tree in the usual heap-array format.
Example
Input:
7
4 9 9 1 5 5 1
Output: true
Constraints
1 <= number of nodes <= 1000-100 <= node value <= 100
How it's graded
- Run checks your code against the examples. Submit also runs a hidden suite in four groups - basic cases, edge cases, random inputs and performance tests at the size limit - and shows which groups pass, never the hidden inputs.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
- Once you pass, you see the approaches from brute force to optimal, and where your solution lands among them.
More problems in Binary Tree Mirror & Symmetry
- Mirror TreeFree
Solve it Symmetric Tree free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime