Dsa
Trees
Warm-up
Symmetric Tree Check
Create a function that checks whether a binary tree is symmetric around its center. A tree is symmetric if the left subtree is a mirror reflection of the right subtree.
Input format:
- The first line contains an integer N, the number of nodes in the tree.
- The next N lines contain two integers L and R, representing the left and right children of each node respectively, where -1 indicates no child.
Output format:
- Output 'Yes' if the tree is symmetric, otherwise output 'No'.
Example:
Input:
3
1 1
-1 -1
-1 -1
Output:
Yes
Key concepts
treesmirrorrecursion
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now