Input: nums = [2,3,1,1,4]
Output: 2
Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
class Solution:
def jump(self, nums: List[int]) -> int:
N = len(nums)
# Initialize
dp = [float("inf")] * N
dp[-1] = 0
for i in range(len(nums)-2,-1,-1):
for j in range(i+1, min(i+nums[i]+1, N)):
dp[i] = min(dp[i], 1 + dp[j])
return dp[0]