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

preview_player
Показать описание
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.

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:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#leetcode #programming #interview
Рекомендации по теме
Комментарии
Автор

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

ashok
Автор

Your channel helps me understand binary trees so much

Dragonchaserk
Автор

Every videos has 110% of good explanation.

kanaramjangid
Автор

Great job to the creators for delivering such a high-quality video! really enjoyed watching this video! The content was clear and saving time very much.

suresharakala
Автор

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

TamilarasiM-gsfb
Автор

Man : On all your series, you tried !!! ... Thank you so much as you continue to saves life.

glaide
Автор

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.

fortunefunda
Автор

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

susmitapatil
Автор

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 😇

minnikeswarrao
Автор

At 13:46, i am confused, already root.left and root.right are swapped, so first 7 and then 2 are added to queue but you are saying opposite, how is that possible?

rajeshberepalli
Автор

Why are there so less likes on this video, this is so informative. I have seen more likes on stupid content and this quality content is getting lesser likes. Great work Nikhil Bhiaya!

anushkamathur
Автор

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?

anirudhv
Автор

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

lemui
Автор

2523. Closest Prime Numbers in Range

please make a solution for this i am trying to solve it from feb 24

premmore
Автор

My question is when we insert into queue should not it insert 7, 2 instead 2, 7

PratibhaSharma-hb
Автор

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?

evadranuvvuu
Автор

And it’s in Java ! Most people use python

Dragonchaserk
welcome to shbcf.ru