← Back to experiences
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/experiences/…$
Check whether the end of an array can be reached from starting. You can jump as many steps from any index as the value of the element at that index. (You need to return boolean value)
For e.g. in the following array [1, 2, 4, 6] you can reach the end by starting from index 0, then you can jump to index 1, now you can jump to either index 2 or 3 since the value at 1st index is 2.
[1, 2, 1, 0, 3] in this array you cannot reach the end since value at index 3 is 0 and hence you cannot move forward from there.
The interviewer was expecting O(n) time complexity but I could only come up with O(n2), rejected :(
Would appreciate if anyone can help me with the solution for this.