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.
The idea is to use a traversal similar to post-order traversal for converting a given n-ary tree into its mirror image. The algorithm is very similar to the algorithm of creating a mirror tree for a binary tree. You might want to check out this post.
In function convertToMirror(TreeNode root), first we convert all sub-trees rooted at child nodes of root to their mirror images(by making recursive calls) and then reverse the order of child nodes themselves.
The time complexity for this approach would be O(n). In the code snippet, checkout function convertToMirror(TreeNode root) for implementation details.
Support us by whitelisting IDeserve in your ad-blocker.