Hi everyone, let's do this question.
Given the root of a binary tree, invert the tree and return its root.
Invert means swap every left node for its corresponding right node or get the mirror image.
So for example, if this is the binary tree which is given, you can see that these two are swapped.
So we have three and two over here.
Now these two are swapped.
So we have five and four over here.
This is the left node right of two.
So but over here you can see this has become the right node of two.
Similarly these two are also swapped.
And we have instead of six and seven we have seven and six.
So this is the question.
Now let's go ahead and write a few test cases for this question.
We've already seen that if this is the tree which is given to us, we have to get this as the output.
Now if this is the tree over here, you can see this is null, right.
So in that case over here this would be seven and null.
So that's the only difference between these two.
And then if you are given a tree with only the root then the mirror image or the uh the case where we
swap the corresponding left and right uh nodes will also have will be looking the same.
Right.
So if this is given, then the output also will be just a tree with one node.
All right.
So this is the question that we are trying to do.
We have understood the question and we have written a few test cases.
So in the next video let's try to think how we can solve this question.