Symmetric Binary Tree
Updated
Problem statement
Imagine flipping the tree rooted at root left to right, like a page held up to a mirror. Return true when the flipped tree is exactly the same as the original, values included, and false when it differs anywhere.
Put another way: the root's two sides must be reflections of each other. Paired nodes hold equal values, and one node's left child pairs with its twin's right child.
Function
isSymmetric(root: TreeNode) → booleanExamples
Example 1
root = [7,4,4,9,null,null,9]return = trueThe left 4 has a 9 on its left, and the right 4 has a 9 on its right. Each side is the other's reflection, so the answer is true.
Example 2
root = [5,3,3,1,2,1,2]return = falseBoth children are 3, but the left one has 1, 2 from left to right and the right one also has 1, 2. A reflection would need 2, 1 on the right, so the answer is false.
Example 3
root = [0,-3,-3,null,null,null,6]return = falseThe two -3 nodes match, but only the right one has a child (6, on its right). The left -3 has no left child to reflect it, so the answer is false.
Constraints
- The number of nodes in the tree is between
1and1000. -100 <= Node.val <= 100
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- 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
- Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
- Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Vertical Order Traversal of a Binary TreeTokopedia · ONSITE INTERVIEWTokopedia interview questions
Capital One interview experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences
- Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)