FastPrepMirror Image Binary Trees
Problems/Mirror Image Binary Trees

Mirror Image Binary Trees

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An Expedia SWE intern review from Gurgaon, India, dated September 2024, includes this question without saying which round asked it. The candidate's process had a coding test and then a two-hour interview on data structures and algorithms, and we place the question in that interview. The review only names the task: decide if one binary tree is the mirror of the other.

No examples or limits are given. Here, the values must match as well as the shape. Two empty trees count as mirror images. Each tree has at most 500 nodes with values from -10^4 to 10^4.

Our version is about 90% the same as the reported question.

You are given the roots of two binary trees, first and second. Return true if the two trees are mirror images of each other, and false otherwise.

Think of holding first up to a mirror. You get its mirror image by swapping the left and right child of every node. The two trees are mirror images when that mirror image is exactly second: the same shape and the same value in every matching place.

Put another way:

  • Two empty trees are mirror images.
  • An empty tree and a non-empty tree are not.
  • Two non-empty trees are mirror images when their roots have the same value, the left subtree of first mirrors the right subtree of second, and the right subtree of first mirrors the left subtree of second.

Function

areMirrors(first: TreeNode, second: TreeNode) → boolean

Examples

Example 1

first = [1,2,3,4,5]second = [1,3,2,null,null,5,4]return = true
first
12453
second
13254

Swap the left and right children of every node in first. Node 1 then has 3 on the left and 2 on the right, and node 2 has 5 on the left and 4 on the right. That is exactly second, so the answer is true.

Example 2

first = [1,2,3]second = [1,2,3]return = false
first
123
second
123

The two trees are the same, but they are not mirror images. The mirror of first has 3 as the left child of the root, while second has 2 there, so the answer is false.

Example 3

first = [7,7]second = [7,7]return = false
first
77
second
77

Every value is 7, but the shapes do not mirror each other. In first the second node is a left child, so in a mirror image it would have to be a right child. In second it is also a left child, so the answer is false.

Constraints

  • Each tree has between 0 and 500 nodes.
  • -10^4 <= Node.val <= 10^4

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Maximum Supplier ProfitONSITE INTERVIEW · Seen Aug 2024

Similar questions at other companies

  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Symmetric Binary TreeFigma · ONSITE INTERVIEWFigma interview questions
  • Tree Level with the Most NodesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Mirror a Binary TreeAMD · ONSITE INTERVIEWAMD interview questions
  • Find a Node’s Level in an N-ary TreeMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Symmetric Binary TreeCapital One · ONSITE INTERVIEWCapital One interview questions
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Vertical Order Traversal of a Binary TreeTokopedia · ONSITE INTERVIEWTokopedia interview questions

Interview reports that mention this question

  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean areMirrors(TreeNode first, TreeNode second) {
        // Write your code here.
    }
}
Checking account…