Leetcode 1428 Solution
This article provides solution to leetcode question 1428 (jump-game-iii)
Access this page by simply typing in "lcs 1428" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/jump-game-iii
Solution
class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
q = collections.deque()
q.append(start)
left = set(range(len(arr)))
left.remove(start)
while q:
i = q.popleft()
if arr[i] == 0:
return True
if i - arr[i] in left:
q.append(i - arr[i])
left.remove(i - arr[i])
if i + arr[i] in left:
q.append(i + arr[i])
left.remove(i + arr[i])
return False