Hey there and welcome back.
Let's get started with another interesting coding interview question, which is the jump game question.
The question reads you are given an integer array Numb's.
You are initially positioned at the array's first index, and each element in the array represents your
maximum jump length at that position.
Return true if you can reach the last index or false otherwise.
So the question is pretty straightforward, and we're given two examples.
In the first example, the array which is given to us is 1341121.
And it's mentioned that initially we are over here and we need to check whether we can reach the last
index of the given array.
And every value is the maximum jump length that you can take from that particular index.
Now, if this is the array which is given to you, and we start from this place over here, you could
make one jump and reach over here and from here you could reach over here by jumping three positions.
And then you can come over here.
And from here you can come over here.
And again, remember, the value at every index just represents the maximum jump length.
So for example from here the maximum that you can jump is two indices.
But again one is less than two.
So you can jump to this position as well.
So that's why if this is the input array the expected output is true.
Now we are given one more example.
So if the input array is 134211011, the expected output is false.
Now why is that the case.
Let's try to understand that.
So we again starting at this index.
And we could take a jump of length one and reach over here.
And from here let's say we are taking a jump of length three.
We reach over here.
And from here I can take a jump of length one.
I reach over here, and from here again I take a jump of length one and I reach over here.
But from this place over here I cannot move forward.
Right.
And that means I can't reach the last index.
Now, another path that I could try is maybe initially, I take a jump from here to here, and then
from here I take a jump to this position over here because again, remember three just represents the
maximum jump length.
And a jump length of one is less than three.
So I can reach over here from here.
And once I'm over here let's say I take a jump of length four.
And again notice I reach over here and after I reach this position I cannot move forward.
So whatever combination you try, you will see that you will finally reach over here and then you're
not able to move forward.
And for that reason, if this is the input array, the expected output is false.
So this is the question at hand.
Now in the next video let's discuss what approach we can take to solve this question.