1
00:00:00,920 --> 00:00:03,260
Hi everyone, let's do this question.

2
00:00:03,260 --> 00:00:08,450
Given the root of a binary tree, invert the tree and return its root.

3
00:00:08,480 --> 00:00:14,480
Invert means swap every left node for its corresponding right node or get the mirror image.

4
00:00:14,480 --> 00:00:19,670
So for example, if this is the binary tree which is given, you can see that these two are swapped.

5
00:00:19,670 --> 00:00:21,350
So we have three and two over here.

6
00:00:21,350 --> 00:00:22,760
Now these two are swapped.

7
00:00:22,760 --> 00:00:25,340
So we have five and four over here.

8
00:00:25,340 --> 00:00:27,260
This is the left node right of two.

9
00:00:27,290 --> 00:00:30,080
So but over here you can see this has become the right node of two.

10
00:00:30,080 --> 00:00:32,210
Similarly these two are also swapped.

11
00:00:32,210 --> 00:00:35,390
And we have instead of six and seven we have seven and six.

12
00:00:35,390 --> 00:00:36,680
So this is the question.

13
00:00:36,680 --> 00:00:40,460
Now let's go ahead and write a few test cases for this question.

14
00:00:40,460 --> 00:00:45,620
We've already seen that if this is the tree which is given to us, we have to get this as the output.

15
00:00:45,620 --> 00:00:49,490
Now if this is the tree over here, you can see this is null, right.

16
00:00:49,490 --> 00:00:52,400
So in that case over here this would be seven and null.

17
00:00:52,400 --> 00:00:54,470
So that's the only difference between these two.

18
00:00:54,470 --> 00:01:01,280
And then if you are given a tree with only the root then the mirror image or the uh the case where we

19
00:01:01,280 --> 00:01:06,320
swap the corresponding left and right uh nodes will also have will be looking the same.

20
00:01:06,320 --> 00:01:06,500
Right.

21
00:01:06,500 --> 00:01:10,850
So if this is given, then the output also will be just a tree with one node.

22
00:01:10,850 --> 00:01:11,360
All right.

23
00:01:11,360 --> 00:01:13,400
So this is the question that we are trying to do.

24
00:01:13,430 --> 00:01:16,310
We have understood the question and we have written a few test cases.

25
00:01:16,310 --> 00:01:20,390
So in the next video let's try to think how we can solve this question.
