Jump Game

You are given an array of non-negative integers nums and start at index 0. From index i you may jump forward to any index from i + 1 up to i + nums[i] (so nums[i] is the longest jump allowed from there, and a 0 means you can't move from it).

Return true if you can reach the last index, and false otherwise.

Constraints

  • 1 <= nums.length <= 10^4
  • 0 <= nums[i] <= 10^5

Examples

Example 1

Input: nums = [2,0,3,0,1]
Output: true

Jump from index 0 to index 2 (2 steps), then from index 2 jump 2 more steps to the last index.

Example 2

Input: nums = [1,1,0,2,4]
Output: false

Every route lands on index 2, whose value is 0. Nothing before it can jump past it, so index 4 is out of reach.

Example 3

Input: nums = [0]
Output: true

You start on the last index, so there is nothing to do.

JavaScript you'll use: Numbers, Math and integer tricks Arrays: create, read, update

/**
 * @param {number[]} nums
 * @return {boolean}
 */
function canJump(nums) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.