Dsa
Trees
Warm-up
Mirror Tree
Write a function that checks whether a given binary tree is its own mirror image. Print "YES" if it is a mirror tree, or "NO" otherwise.
Input Format:
- The first line will be an integer `n`, the number of nodes.
- The next `n` lines will contain three integers each: `value`, `left_index`, `right_index`, where left_index and right_index are -1 if there is no child in that position.
Output Format:
- Print "YES" or "NO" based on whether the tree is a mirror of itself.
Example:
Input:
3
1 1 2
2 -1 -1
2 -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