Jump game
You stand on position 0 of a list nums of non-negative integers. Each number is the longest jump you may make from its position: from position i you may move forward to any position from i + 1 up to i + nums[i]. A 0 means you cannot move on from there.
Return True if some sequence of jumps reaches the last position, and False otherwise. You choose each jump's length, so a big number never forces you past the end.
nums = [2, 3, 0, 1, 4]OutputTrueJump 1 place to position 1, then 3 places to position 4, the last one.
nums = [1, 2, 0, 0, 3]OutputFalsePositions 0 and 1 reach at most position 3. Positions 2 and 3 hold 0, so position 4 is out of reach.
nums = [0]OutputTrueYou already stand on the last position.
1 ≤ len(nums) ≤ 105
0 ≤ nums[i] ≤ 105
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.