Tree Same Tree
Published at25 Jul 2026
Created by M Ichsanul Fadhil
Given two arrays representing binary trees, determine if they are identical (same structure and same values at each position).
Example Input & Output
Example 1
Input
[1,2],[1,2,3]
Output
false
Explanation
Different sizes
Example 2
Input
[1],[1]
Output
true
Explanation
Single node
Example 3
Input
[1,2,3],[1,2,4]
Output
false
Explanation
Different values
Example 4
Input
[1,2,3],[1,2,3]
Output
true
Explanation
Identical trees
Example 5
Input
[],[1]
Output
false
Explanation
Different sizes
Algorithm Flow

Recommendation Algorithm Flow for Tree Same Tree
Solution Approach
Best Answers
java
class Solution {
public boolean solution(int[] a, int[] b) {
return java.util.Arrays.equals(a,b);
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
