Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Can You Pass? by lxf42
def can_pass(matrix, first, second):
sx, sy = first
ex, ey = second
val = matrix[sx][sy]
visited = set(first)
queue = [(sx, sy)]
while queue:
x, y = queue.pop()
for nx, ny in (x-1, y), (x+1, y), (x, y-1), (x, y+1):
try:
if (nx, ny) not in visited and matrix[nx][ny] == val:
if nx == ex and ny == ey:
return True
visited.add((nx, ny))
queue.append((nx, ny))
except IndexError:
pass
return False
June 16, 2022
Comments: