Jump Game VII LeetCode solution in Python

1
class Solution:
2
def canReach(self, s: str, minJump: int, maxJump: int) -> bool:
3
# dp[i] represents whether i is reachable
4
dp = [False for _ in s]
5
dp[0] = True
6

7
for i in range(1, len(s)):
8
if s[i] == "1":
9
continue
10

11
# iterate through the solutions in range [i - maxJump, i - minJump]
12
# and if any previous spot in range is reachable, then i is also reachable
13
window_start = max(0, i - maxJump)
14
window_end = i - minJump
15
for j in range(window_start, window_end + 1):
16
if dp[j]:
17
dp[i] = True
18
break
19

20
return dp[-1]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0