Hello all and welcome back.
So in this video I'm going to discuss a question which you have to do.
So the question or rather the operation is we have to search in a linked list, but this time by an
index okay.
So you have to do both the iterative.
As well as the recursive approach okay.
Now if we think on this question it's going to be a lot similar to many questions or operations which
we have done.
So I'm pretty sure that now you will be a lot comfortable.
If you have actually tried the previous assignment, then you will surely be able to do that or do this
question.
If not, then you might feel this difficulty.
So instead of uh, just solving this question, please make sure that you solve the previous question
as well.
So one two.
So let me just discuss approach with you still so that you can just try it better.
Now if I have to get the index or sorry search by an index, you will be giving me the index.
Now I don't know if that index actually is there or not.
For example, in this five is one index which I know is not there.
Okay.
But at the same time we know that overall 0 to 4 are there.
Okay.
So again the approach is going to be the same.
We are going to make a temp variable which will start from head.
We will be keeping on increasing our index.
Sorry.
We can just have a count right.
We can have a count and we can start with temp and count a lot similar to what we did in insert and
delete at index.
If you are able to find the index which I have given you, for example, let's say I gave you index
two.
When your count becomes equals to two, you will find this.
So you can return me the answer.
And if you go to the end of your linked list, that is your temp becomes none and you are still not
able to find it, then your answer is going to be minus one or not found.
Okay, so great everyone!
I hope you will give this a try and will be able to do that.
Please make sure that you are able to solve this question.
The solution will be present, but I want all of you to now try and solve this question.
That's why I'm asking you separately in this particular video.
Because we have done so many of these operations, there will be a lot easy for you to do now.
Thank you.