Check Whether a Toutiao Comment Reply Tree Is Mirror Symmetric

Last updated: November 29, 2026

Quick Overview

Given a binary tree of comment reaction scores from a Toutiao reply layout experiment, return True if the tree is a mirror image of itself around its root.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a binary tree of comment reaction scores from a Toutiao reply layout experiment, return True if the tree is a mirror image of itself around its root.

A quick binary tree problem used in ByteDance phone screens to check recursion fluency before a harder follow-up. The interviewer checks that you compare outer and inner pairs correctly and can switch to an iterative version.

What the Interviewer Expects
  • Compare left subtree to right subtree, not each to itself
  • Pair outer children together and inner children together
  • Handle None pairs before reading values
  • Offer an iterative version to avoid recursion limits
  • State O(n) time
Key Topics to Cover
binary trees
recursion
iterative traversal
tree comparison
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
  • Return the depth of the first level that breaks symmetry.
  • Make the tree symmetric with the fewest value changes.
  • Check symmetry of an n-ary tree.
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: the root of a binary tree, possibly None. Output: True if the left subtree is a mirror of the right subtree, meaning values match and structure is reflected. An empty tree and a single node are...

High-Level Design

Two subtrees a and b are mirrors if their roots have equal values, a.left mirrors b.right, and a.right mirrors b.left. Push the pair (root.left, root.right) on a stack and keep checking pairs, pushing...


Submit Your Answer
Markdown supported