[Python] Jump Game III with queue (deque) + visited set
BFS to iterate through all indexes connected to starting index. Storing already explored indices allows us to ensure that we only explore each index a single ti
BFS to iterate through all indexes connected to starting index. Storing already explored indices allows us to ensure that we only explore each index a single time.\n\t\n\tdef canReach(self, arr, start):\n        \n        q = collections.deque()\n        q.append(start)\n        visited = set()\n        \n        while q:\n            cur_i = q.popleft()\n            \n            if arr[cur_i] == 0:\n                return True\n            \n            a, b = cur_i + arr[cur_i], cur_i - arr[cur_i]\n            \n            if a < len(arr) and a not in visited:\n                q.append(a)\n                visited.add(a)\n            if b >= 0 and b not in visited:\n                q.append(b)\n                visited.add(b)\n                \n        return False
[]