Problem statement

https://binarysearch.com/problems/Number-of-Hops/

Solution

Equal to Leetcode 0045. Jump Game II.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, nums):
        t = list(accumulate([i + num for i, num in enumerate(nums)], max))
        ind, q = 0, 0
        while ind < len(nums) - 1:
            ind = t[ind]
            q += 1
        return q