Given a tree, convert the tree to its corresponding mirror tree. A mirror tree of a tree is where left node of the root of the tree is right node of the mirror tree and right node of the tree is left node of mirror tree and left and right subtrees of the root are also mirror trees. Example 1: Tree: 1 2 3 4 5
Mirror Tree: 1 3 2 5 4
Video coming soon!
Subscribe for more updates
Preparing for interviews? IDeserve team is here to help.
Create your profile
Create your profile, and here is what you will get:
1: Interview practice platform.
2: Once you are ready to take the interview, IDeserve team will help you get connected to the best job opportunities.
3: Personalized mentorship from IDeserve team once your interview process has started.
Creation of profile shouldn't take more than 2 minutes.
Boundary condition: If root is null, then return. Recursive step: Recursively convert left and right sub trees to their mirror. Actual conversion to mirror: Swap left and right sub trees of the current node. Please checkout code snippet and algorithm visualization section for understanding the algorithm.
Support us by whitelisting IDeserve in your ad-blocker.