Leetcode 2001 Solution

This article provides solution to leetcode question 2001 (jump-game-vii)

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

Solution

class Solution: def canReach(self, s: str, minJump: int, maxJump: int) -> bool: q = collections.deque() q.append(0) farthest = 0
while q: i = q.popleft()
if s[i] != '0': continue
if i == len(s) - 1: return True
for j in range( max(i + minJump, farthest + 1), min(i + maxJump + 1, len(s)), ): q.append(j) farthest = j
return False