Symmetric Binary Tree
Updated
Problem statement
You are given the root of a binary tree. Return true if the tree is symmetric, meaning its left side is a mirror image of its right side. Otherwise return false.
Two subtrees mirror each other when all of these hold:
- Their roots have the same value.
- The left subtree of one mirrors the right subtree of the other.
- The right subtree of one mirrors the left subtree of the other.
Function
isSymmetric(root: TreeNode) → booleanExamples
Example 1
root = [1,2,2,3,4,4,3]return = trueThe root's two children have the same value. Their outer children match each other, and their inner children match each other. Every mirrored pair is equal, so the answer is true.
Example 2
root = [1,2,2,null,3,null,3]return = falseThe root's two children have the same value. Each of them has one child with value 3, and both of those children hang on the right side. In a mirror image they would hang on opposite sides, so the answer is false.
Example 3
root = []return = trueThe tree is empty. There is nothing to compare, so it counts as symmetric and the answer is true.
Constraints
- The tree contains at most
10^5nodes. - Each node value fits in a signed 32-bit integer.
- The empty tree is symmetric.
More DocuSign Phone Screen questions
- Union Area of Two RectanglesPHONE SCREEN · Seen Oct 2026
- Execute Cursor-Based Text Editor OperationsPHONE SCREEN · Seen Sep 2026
- Minimize Array Sum After K Halving OperationsPHONE SCREEN · Seen Sep 2026
- Fizz and Buzz Words From 1 to nPHONE SCREEN · Seen Sep 2026
- Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Rain Kept Between WallsPHONE SCREEN · Seen Mar 2026
- Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Rebuild a Trip From Flight TicketsPHONE SCREEN · Seen Apr 2019
- Find the Words for Each PrefixPHONE SCREEN · Seen Sep 2018
Similar questions at other companies
- Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Left View of a Binary TreeMygate · PHONE SCREENMygate interview questions
- Mirror a Binary TreeAdobe · PHONE SCREENAdobe interview questions
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Tree Height After Child PromotionSnowflake · PHONE SCREENSnowflake interview questions
- Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Tree DiameterQualcomm · PHONE SCREENQualcomm interview questions
- Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
- Distance Between Two Nodes in a Binary TreeBloomberg LP · PHONE SCREENBloomberg LP interview questions