Check Whether a Gift Bundle Tree Is a Mirror of Itself

Last updated: November 29, 2026

Quick Overview

Gift bundles at Amazon are displayed as a binary tree of item IDs. Return True if the tree is symmetric around its root, meaning the left subtree is a mirror image of the right subtree.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Gift bundles at Amazon are displayed as a binary tree of item IDs. Return True if the tree is symmetric around its root, meaning the left subtree is a mirror image of the right subtree.

A warm-up in the style of Amazon's online assessment, framed around a gift-wrap layout service that renders bundles symmetrically. The interviewer checks that you compare the right pairs of nodes and can give both a recursive and an iterative version.

What the Interviewer Expects
  • Identify that symmetry compares outer pairs and inner pairs, not left to left
  • Handle empty trees and single nodes cleanly
  • Write a recursive solution in a few lines
  • Offer an iterative queue-based version to avoid deep recursion
  • State O(n) time and O(h) space
Key Topics to Cover
binary trees
recursion
BFS
tree symmetry
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
  • How would you avoid a stack overflow on a tree that is 100,000 levels deep?
  • How would you check whether two separate bundle trees are mirrors of each other?
  • What changes if symmetry should compare only structure and ignore values?
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 the root of a binary tree (possibly empty). Output is a boolean. The tree is symmetric when, for every pair of mirrored positions, both are missing or both exist with equal values. An empty t...

High-Level Design

Mirror two subtrees together. Two nodes a and b are mirrors when their values match, a.left mirrors b.right (the outer pair), and a.right mirrors b.left (the inner pair). Start with the pa...


Submit Your Answer
Markdown supported