Invert Binary Tree (LeetCode 226) | Full solution with diagrams and animations | Study Algorithms

Inverting a binary tree is more synonymous with mirroring a binary tree. Try to assume that there is a mirror in front of the tree and you need to return the reflection. This video explains beautifully with diagrams and animations how the reflection looks like and how to create one. All of this is done using a level order traversal technique.
Actual Problem: leetcode.com/problems/invert-...
Chapters:
00:00 - Intro
00:58 - Problem Statement and Description
03:15 - The thought behind the approach
05:44 - Recursive Solution
08:56 - Level Order Traversal Trick
12:05 - Dry-run of Code
14:28 - Final Thoughts
📚 Links to topics I talk about in the video:
LeetCode Problems: • Leetcode Solutions
Level Order Traversal: • Level order traversal ...
Post Order Traversal: • Post-order traversal o...
Tree Data Structure: • Understanding Tree Dat...
📘 A text based explanation is available at: studyalgorithms.com
Code on Github: github.com/nikoo28/java-solut...
Test-cases on Github: github.com/nikoo28/java-solut...
📖 Reference Books:
Starting Learn to Code: amzn.to/36pU0JO
Favorite book to understand algorithms: amzn.to/39w3YLS
Favorite book for data structures: amzn.to/3oAVBTk
Get started for interview preparation: amzn.to/39ysbkJ
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
🎥 My Recording Gear:
Recording Light: amzn.to/3pAqh8O
Microphone: amzn.to/2MCX7qU
Recording Camera: amzn.to/3alg9Ky
Tablet to sketch and draw: amzn.to/3pM6Bi4
Surface Pen: amzn.to/3pv6tTs
Laptop to edit videos: amzn.to/2LYpMqn
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Follow on Twitter at: / studyalgorithms
Follow on Tumblr at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#leetcode #programming #interview

Пікірлер: 19

  • @ashok2089
    @ashok208910 күн бұрын

    Others: Let's explain recursive approach, done. Nikhil: also explains BFS approach! That's why you are a gem!

  • @kanaramjangid8563
    @kanaramjangid856310 күн бұрын

    Every videos has 110% of good explanation.

  • @nikoo28

    @nikoo28

    10 күн бұрын

    Glad you like them!

  • @TamilarasiM-gs8fb
    @TamilarasiM-gs8fb11 ай бұрын

    Thank you so much .After a long search I got clearly explained video

  • @quanganh7094
    @quanganh70947 ай бұрын

    thanks, very comprehensible!!

  • @susmitapatil4847
    @susmitapatil48472 ай бұрын

    Very well explained. Thank you so much for such nice content 🎉

  • @nikoo28

    @nikoo28

    2 ай бұрын

    My pleasure 😊

  • @minnikeswarrao6185
    @minnikeswarrao6185 Жыл бұрын

    Hi sir, First of all big fan of your work🙌 Requesting you to solve "Sum of distances in tree" problem of leetcode... I have gone through many videos but none of them are clear... Looking forward for your explanation 😇

  • @subee128
    @subee1286 ай бұрын

    Thanks

  • @fortunefunda4171
    @fortunefunda41713 ай бұрын

    Sir at 13:42 you added 2 and 7 to the Queue but shouldn't 7 and 2 be added to Queue because you did swapping before this . I really liked your explanation but having this little doubt. Please clear this minor doubt.

  • @garvitarora7777

    @garvitarora7777

    3 ай бұрын

    yes you are right

  • @nikoo28

    @nikoo28

    3 ай бұрын

    Yep…sorry for the confusion

  • @evadranuvvuu
    @evadranuvvuu3 күн бұрын

    if(root == null) { return null; } TreeNode temp=root.left; root.left=root.right; root.right=temp; invertTree(root.left); invertTree(root.right); return root; Sir this one take o(1)space? Then why using queue sir? Please any one explain?

  • @lemui2075
    @lemui207510 ай бұрын

    Thank you so much for video with explaination. May I check with you, why you put the keyword "final" in front of Queue ?

  • @nikoo28

    @nikoo28

    10 ай бұрын

    you can remove the "final" keyword if you like. It is not necessary in this implementation. :)

  • @anirudhv0062
    @anirudhv00623 ай бұрын

    why is the Linked List implementation of the queue being used here? can we use other thing like deque or other implementation of queue also?

  • @nikoo28

    @nikoo28

    3 ай бұрын

    Yes

  • @anirudhv0062

    @anirudhv0062

    3 ай бұрын

    @@nikoo28 Thanks! Your explanations are awesome

  • @ascreations1396
    @ascreations13966 ай бұрын

    😃😃😃😃😃😃😃😃😃

Келесі