1306. Jump Game III
class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
q = deque([start])
visited = set()
visited.add(start)
directions = [1, -1]
while q:
size = len(q)
node = q.popleft()
if arr[node] == 0:
return True
for d in directions:
nextPos = node + arr[node]*d
if 0 <= nextPos < len(arr) and nextPos not in visited:
q.append(nextPos)
visited.add(nextPos)
return False