Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5578 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 714 |
@Manikanta punnam | 587 |
@sriramgoparaju99 | 532 |
@praveenbgp6 | 525 |
@yashkaril4 | 517 |
@prankursharma31 | 489 |
@rdakka | 467 |
@sonamnigam1999 | 441 |
@sonamkumari63928 | 427 |
@purohitmn02 | 427 |
@shubhamstudent5 | 419 |
Complete Leaderboard |
Given an positive integer N and a list of N integers A[]. Each element in the array denotes the maximum length of jump you can cover. Find out if you can make it to the last index if you start at the first index of the list.
Example 1:
Input: N = 6 A[] = {1, 2, 0, 3, 0, 0} Output: 1 Explanation: Jump 1 step from first index to second index. Then jump 2 steps to reach 4th index, and now jump 2 steps to reach the end.
Example 2:
Input: N = 3 A[] = {1, 0, 2} Output: 0 Explanation: You can't reach the end of the array.
Your Task:
You don't need to read input or print anything. Your task is to complete the function canReach() which takes a Integer N and a list A of size N as input and returns 1 if the ned of the array is reachable, else return 0.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 105
1 <= A[i] <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes