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

  Рет қаралды 6,935

Nikhil Lohia

Nikhil Lohia

Күн бұрын

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

Пікірлер: 15
@TamilarasiM-gs8fb
@TamilarasiM-gs8fb 10 ай бұрын
Thank you so much .After a long search I got clearly explained video
@quanganh7094
@quanganh7094 7 ай бұрын
thanks, very comprehensible!!
@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 😇
@susmitapatil4847
@susmitapatil4847 Ай бұрын
Very well explained. Thank you so much for such nice content 🎉
@nikoo28
@nikoo28 Ай бұрын
My pleasure 😊
@subee128
@subee128 6 ай бұрын
Thanks
@fortunefunda4171
@fortunefunda4171 2 ай бұрын
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 2 ай бұрын
yes you are right
@nikoo28
@nikoo28 2 ай бұрын
Yep…sorry for the confusion
@lemui2075
@lemui2075 9 ай бұрын
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 9 ай бұрын
you can remove the "final" keyword if you like. It is not necessary in this implementation. :)
@anirudhv0062
@anirudhv0062 2 ай бұрын
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 2 ай бұрын
Yes
@anirudhv0062
@anirudhv0062 2 ай бұрын
@@nikoo28 Thanks! Your explanations are awesome
@ascreations1396
@ascreations1396 6 ай бұрын
😃😃😃😃😃😃😃😃😃
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 28 МЛН
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 112 МЛН
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 62 МЛН
Khóa ly biệt
01:00
Đào Nguyễn Ánh - Hữu Hưng
Рет қаралды 21 МЛН
Invert Binary Tree | Leetcode #226
6:39
Techdose
Рет қаралды 54 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 610 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 288 М.
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 28 МЛН