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

Поделиться
HTML-код
  • Опубликовано: 2 авг 2024
  • 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
    @ashok2089 19 дней назад +1

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

  • @kanaramjangid8563
    @kanaramjangid8563 19 дней назад +2

    Every videos has 110% of good explanation.

    • @nikoo28
      @nikoo28  19 дней назад

      Glad you like them!

  • @TamilarasiM-gs8fb
    @TamilarasiM-gs8fb 11 месяцев назад +2

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

  • @quanganh7094
    @quanganh7094 8 месяцев назад +1

    thanks, very comprehensible!!

  • @minnikeswarrao6185
    @minnikeswarrao6185 Год назад +2

    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 😇

  • @susmitapatil4847
    @susmitapatil4847 2 месяца назад +1

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

    • @nikoo28
      @nikoo28  2 месяца назад

      My pleasure 😊

  • @subee128
    @subee128 7 месяцев назад +1

    Thanks

  • @fortunefunda4171
    @fortunefunda4171 3 месяца назад +3

    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 месяца назад +1

      Yep…sorry for the confusion

  • @lemui2075
    @lemui2075 11 месяцев назад

    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. :)

  • @evadranuvvuu
    @evadranuvvuu 12 дней назад

    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?

  • @anirudhv0062
    @anirudhv0062 3 месяца назад +1

    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
    @ascreations1396 7 месяцев назад +1

    😃😃😃😃😃😃😃😃😃