6. Symmetric Tree
easyAsked at FlipkartDecide whether a binary tree is a mirror of itself — Flipkart uses it as a quick recursion warm-up before moving to inventory-tree questions.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given the root of a binary tree, check whether it is a mirror of itself (symmetric around its center). Return true if symmetric.
Constraints
1 <= nodes <= 1000-100 <= Node.val <= 100
Examples
Example 1
root = [1,2,2,3,4,4,3]trueExample 2
root = [1,2,2,null,3,null,3]falseApproaches
1. Brute force level capture
BFS each level into an array and check palindrome with nulls preserved.
- Time
- O(n)
- Space
- O(n)
// level-order with nulls, then for each level check palindrome
// extra memory, easy bug to drop nullsTradeoff:
2. Mirror DFS
Recurse on (left.left, right.right) and (left.right, right.left) in lockstep. Constant extra work per node.
- Time
- O(n)
- Space
- O(h)
function isSymmetric(root) {
const mirror = (a, b) => {
if (!a && !b) return true;
if (!a || !b) return false;
return a.val === b.val
&& mirror(a.left, b.right)
&& mirror(a.right, b.left);
};
return !root || mirror(root.left, root.right);
}Tradeoff:
Flipkart-specific tips
Flipkart panels reward candidates who call out the null-vs-value asymmetry trap — it parallels their nullable attribute checks in category metadata.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill Symmetric Tree and other Flipkart interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →