"""
https://leetcode.com/problems/jump-game-ii/
"""

from typing import List


class Solution:
    def jump(self, nums: List[int]) -> int:
        if len(nums) <= 1:
            return 0
        l, r, jumps = 0, nums[0], 1
        while r < len(nums) - 1:
            jumps += 1
            n = max(i + nums[i] for i in range(l, r + 1))
            l, r = r, n
        return jumps

"""
https://leetcode.com/problems/jump-game-ii/
"""

from typing import List


class Solution:
    def jump(self, nums: List[int]) -> int:
        if len(nums) <= 1:
            return 0
        l, r, jumps = 0, nums[0], 1
        while r < len(nums) - 1:
            jumps += 1
            n = max(i + nums[i] for i in range(l, r + 1))
            l, r = r, n
        return jumps

https://leetcode.com/problems/jump-game-ii/