Check Whether a UI Layout Tree Is Mirror Symmetric

Last updated: November 29, 2026

Quick Overview

Given the root of a binary tree describing a split-pane layout, decide whether the tree is a mirror image of itself around its center.

Google
Coding & Algorithms
Frontend Engineer
Google
November 29, 2026
Frontend Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given the root of a binary tree describing a split-pane layout, decide whether the tree is a mirror image of itself around its center.

Asked in Google frontend phone screens with a framing about checking whether a split-pane layout renders identically in left-to-right and right-to-left locales. The interviewer looks for the insight that you compare two subtrees in opposite directions, not one subtree to itself.

What the Interviewer Expects
  • Recognize that symmetry compares left.left with right.right and left.right with right.left
  • Handle None pairs cleanly as the base case
  • Offer an iterative version using a queue of pairs
  • Analyze O(n) time
  • Test on an asymmetric tree with equal values but different shape
Key Topics to Cover
binary trees
recursion
tree comparison
queue of pairs
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Make the check iterative.
  • How would you mirror the tree in place so the check becomes an equality test?
  • What if nodes carry a width attribute that must also match?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a binary tree root. Return True when the left subtree is the mirror reflection of the right subtree, both in shape and in values. An empty tree is symmetric. Values may repeat, so shape mat...

High-Level Design

Define a helper mirror(a, b) that is true when a and b are reflections: both empty, or both present with equal values, with a.left mirroring b.right and a.right mirroring b.left. The ans...


Submit Your Answer
Markdown supported