You start at index 0 of nums. The value nums[i] is the maximum jump length from index i (you may jump any shorter distance too). Return True if you can reach the last index.
For [2, 3, 1, 1, 4] the answer is True; for [3, 2, 1, 0, 4] it is False.
The starter code works backwards and scans many positions for every index. It is correct but too slow for long lists.
Example 1
Input:
can_jump([2, 3, 1, 1, 4])
Output:
True
Example 2
Input:
can_jump([3, 2, 1, 0, 4])
Output:
False
0 <= len(nums) <= 2000000 <= nums[i] <= 100000No results yet
Run your code to check it against the examples, or submit to run every test.