Symmetric Binary Tree
Updated
Problem statement
Given the root of a binary tree, return true when the tree is symmetric around its center and false otherwise.
Two subtrees mirror each other when their root values are equal, the left subtree of one mirrors the right subtree of the other, and 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 left and right subtrees have equal values in mirrored positions.
Example 2
root = [1,2,2,null,3,null,3]return = falseThe two nodes with value 3 occupy the same side of their parents instead of mirrored sides.
Example 3
root = []return = trueAn empty tree has no mismatched pair, so it is symmetric.
Constraints
- The tree contains at most
10^5nodes. - Each node value fits in a signed 32-bit integer.
- The empty tree is symmetric.
More Figma Onsite Interview questions
- Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 1 (Validate Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Sort Documents Left to RightONSITE INTERVIEW · Seen Aug 2026
- Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
- Nested Template Variable ExpansionONSITE INTERVIEW · Seen Jun 2024
- Parse, Validate, and Repair Markdown FormattingONSITE INTERVIEW · Seen Jun 2024
- Breadth-First Values of a Binary TreeONSITE INTERVIEW · Seen Oct 2022
Similar questions at other companies
- Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn 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
- Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Vertical Order Traversal of a Binary TreeTokopedia · ONSITE INTERVIEWTokopedia interview questions