Hello everyone and welcome back.
So in this video we are going to continue our discussion on recursion and array and solve one more question,
which is going to help us to understand the same a lot more deeply.
So let's get started.
So the question is as on your screen, given an array and an element, we have to find the first index
of the element and last index of the element.
So I will just give you an example so that the question is a lot more clear.
What exactly we have to do is let us say if we are given an array, say the array or a list basically
is
3252821, then we have to tell the first index and the last index.
So it's always a good strategy if like let's say you are given any question, think of a example or
think of actually a you I would say test case and actually write what the answer will be.
Even if you are asked the question in an interview, please make sure that you always and always ask
your interviewer for some example, so that you can make sure that your understanding of the question
and what the interview or what let's say any platform is asking you to solve that is on the same ground.
Now, in this specific question, I am making one more thing clear.
We have to write two separate functions and don't and won't have to do this in a same function.
Okay.
So now let us see what will be the answer.
Everyone.
So if these are the indexes.
Of course my first index and let us say the element which I am given is two.
So my first and last index will actually be one and five respectively.
Right.
Because if you will see in this particular example, two is coming the very first time on first index,
and it is coming on the very last like last time on the fifth index.
Now one more thing.
Always make sure that let's say if you are given ten in this particular question, please make sure
that you also have this thing clear that what exactly we want to do.
So in this particular case, I want to make sure that we return minus one if not found.
So I kept these things I would say unclear in the in this question specifically because I want to make
sure that let's say anytime you are solving this question in an interview, these are the things which
you have to make, I would say clear without actually first starting or like let's say directly jumping
to the solution.
Okay.
So please, please make sure that you are asking and clarifying all these things though.