Dsa
Trees
Medium
Symmetric Binary Tree Checker
Write 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. Read the tree structure from standard input:
- The first line contains an integer, n, number of nodes in the tree.
- The next n lines contain values of the nodes followed by the indexes of the left and right children, where -1 indicates no child.
Output 'Yes' if the tree is symmetric, otherwise output 'No'.
Example:
Input:
3
1 2 2
2 -1 -1
2 -1 -1
Output:
Yes
Key concepts
binary treesymmetricrecursion
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