Hi, everyone.
So in this video, we will be writing the code for this problem and let's start writing the code so
we discuss that.
What do we need?
We are going to write one helper function and what this helper function will do, it will do in order
traversal so fording in order traversal.
We obviously need that riyaz input.
So we will take triazine.
But we discussed that we need one variable count and we need one more variable answer.
And how I will call this function, so initially the value of count to zero, I have not visited any
of the nauseate and initially my answer is, let's say minus one.
Then what I'm going to do, I will call this function in order.
It will take root as input, it will take count as input, it will take answer as input, and it will
take Ghias input.
Obviously, we need to take as input also.
And what this function will do, this function will update the value of answer.
And when you have the value of answer, you can return the answer and the function is in order.
So what it will do, it will perform the traversal.
So for writing the code for another trevathan, it's very simple.
First of all, base case, if your tree does not exist, you will simply on now in artemisinins left-to-right.
So I will call in order and in order on the left.
So count will remain same on several domain same and gavelled remains same.
And now I am visiting the current node.
So you remember the traversal is you are left then data and then right.
So when you are visiting the current node, when you are visiting this node, then you will look on
placeless.
This will be the first node that we will visit.
So let's do that.
So what I will do here is I will do I am visiting the current node, so I will look after this place
and now we need to check.
So if the value of count become a clear Stookey, that means this is our answer.
This is our node.
So if this is our node, what will be my answer?
My answer will be the data, which is route root value and stop.
So we need to stop.
So we will return.
And if this is not the case, then obviously Left-to-right so we'll call the order function on the right
subtree so rude, right, then government will remain same on several domains and cable means him and
that that will be the complete code.
So let's add in our code.
Yeah, our code is working and let's it.
So basically, our court is working and the court is so simple, right?
What they are doing is simple for doing a traversal.
The best case then left, the Spartans left, then this party's data.
You are visiting the current north and this party's right subtree.
Very simple.
As soon as your visiting minority, you are doing Karplus plus.
And since they are, Trevathan is basically sorted.
So as soon as the value of government become Miklaszewski, you will update the answer and you will
return.
And finally, the answer will contain the Naude no data and you will return the answer simple.
And we will discuss the industry's complexity.
So time is big.
Often in worst case you will you have to go through each and every node and space complexity again if
the BSD as coutry.
So space complexity will also be big often.
Right?
So these are the time and the space complexity.
So this is all about this problem.
Guys, I will see you in the next one.
Thank you.