Tree Symmetric Check
Published at25 Jul 2026
Created by M Ichsanul Fadhil
Check if a binary tree represented as an array is symmetric around its center (a mirror of itself). A tree is symmetric if the left subtree is a mirror of the right subtree.
For array representation, compare pairs of nodes at mirror positions across the root. At each level, the leftmost and rightmost nodes should match, moving inward.
Example Input & Output
Example 1
Input
[1,2,2,3,4,4,3]
Output
true
Explanation
Symmetric
Example 2
Input
[1,2,2,3,5,5,3]
Output
true
Explanation
Another symmetric
Example 3
Input
[1,2,2,3,4,5,3]
Output
false
Explanation
Not symmetric: 4!=5
Example 4
Input
[1,2,3]
Output
false
Explanation
Not symmetric: 2!=3
Example 5
Input
[1]
Output
true
Explanation
Single node
Algorithm Flow

Recommendation Algorithm Flow for Tree Symmetric Check
Solution Approach
Best Answers
java
class Solution {
public boolean solution(int[] nums) {
int n=nums.length;if(n<=1)return true;
for(int i=0;i<n;i++){
int lv=31-Integer.numberOfLeadingZeros(i+1);
int first=(1<<lv)-1,last=(1<<(lv+1))-2,mirror=first+last-i;
if(mirror<n&&nums[i]!=nums[mirror])return false;
}return true;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
