FastPrepSymmetric Tree
Problems/Symmetric Tree

Symmetric Tree

Zillow logoZillow● EasyFULLTIMEONSITE INTERVIEW

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow by a candidate for a Software Engineering role in Los Angeles who interviewed in October 2020 and did not get an offer; they found the process fair overall. It opened with a live coding session on an online platform, where the candidate got two medium-level algorithm problems. The last round was two interviews, each with a different engineer: an algorithms interview that the candidate rates as easy, and an interview on working with data in Python. The report lists two questions: whether a binary tree is symmetric, and a task to count duplicate values in a string.

The report does not say which round asked the tree question. Checking whether a tree mirrors itself is a short, easy task, and the report rates the last round's algorithms interview as easy while the first-round problems were medium, so we place it in that algorithms interview and treat the last round as an onsite interview; that is our reading.

The report does not say how the tree reaches the function or how large it can be. Our reading is the well-known version of this task: the function isSymmetric gets the root of the tree, shown in the examples as a level-order list with null for a missing child, and returns true when flipping the tree from left to right gives back the same shape with the same values. The limits (1 to 1,000 nodes, values from -100 to 100) are ours.

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

You get root, the top node of a binary tree. Decide whether this tree is symmetric: return true for a symmetric tree and false for any other tree.

Symmetric means the tree equals its own reflection. Picture a vertical line through the root and swap everything on one side of it with everything on the other, so a node that was a left child turns into a right child, and the other way round. The tree passes when its reflection matches it exactly, in shape and in every value.

The examples write the tree as a level-order list: the root first, then each level from left to right, with null where a child is missing.

Function

isSymmetric(root: TreeNode) → boolean

Examples

Example 1

root = [5,8,8,2,6,6,2]return = true
root
5826862

Both children of the root hold 8. Under the left 8 sit 2 (outer) and 6 (inner); under the right 8 sit 6 (inner) and 2 (outer). Read across, the bottom row is 2, 6, 6, 2, the same backwards, so every node matches its reflection and we return true.

Example 2

root = [4,7,7,1,9,1,9]return = false
root
4719719

Each 7 holds 1 and then 9, reading left to right. The reflection of the left 7 holds 9 and then 1, which does not match the right 7. The bottom row 1, 9, 1, 9 is not the same backwards, so we return false.

Example 3

root = [5,8,8,null,6,null,6]return = false
root
58686

Each 8 holds a single child 6, and each 6 hangs to the right of its parent. Reflected, the 6 below the right-hand 8 would move to the left of that 8. The values line up but the outlines differ, so we return false.

Example 4

root = [0,-5,-5,null,3,3]return = true
root
0-53-53

The left -5 has just one child, 3, hanging to its right; the right -5 has just one child, 3, hanging to its left. Both 3 nodes sit next to the middle line, one on each side, so the reflection is identical and we return true.

Constraints

  • The number of nodes in the tree is between 1 and 1000.
  • -100 <= Node.val <= 100

More Zillow Onsite Interview questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
  • Count Duplicate CharactersONSITE INTERVIEW · Seen Oct 2020
  • Decision Tree Classifier from ScratchONSITE INTERVIEW · Seen Nov 2019
  • Uniform to Normal NumbersONSITE INTERVIEW · Seen Nov 2019
  • Check Each Word in a Character GridONSITE INTERVIEW · Seen Oct 2018
  • Find Median from Data StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2018
  • Is SubstringONSITE INTERVIEW · Seen Nov 2017

Similar questions at other companies

  • Diameter of Binary TreeeBay · ONSITE INTERVIEWeBay interview questions
  • 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 Image Binary TreesExpedia · ONSITE INTERVIEWExpedia 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
  • Serialize and Deserialize a Binary TreeAmazon · ONSITE INTERVIEW
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
All Zillow interview questionsSee Zillow 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 isSymmetric(TreeNode root) {
        // Write your code here.
    }
}
Checking account…