from collections import deque

def solution(warehouse):
    M = len(warehouse)
    N = len(warehouse[0])

    visited = [[False] * N for _ in range(M)]
    queue = deque()

    queue.append((0, 0, 1))
    visited[0][0] = True

    dx = [1, -1, 0, 0]
    dy = [0, 0, 1, -1]

    while queue:
        x, y, dist = queue.popleft()

        if x == M - 1 and y == N - 1:
            return dist

        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < M and 0 <= ny < N:
                if not visited[nx][ny] and warehouse[nx][ny] == 0:
                    visited[nx][ny] = True
                    queue.append((nx, ny, dist + 1))

    return -1


warehouse = [
    [0, 0, 0],
    [1, 1, 0],
    [0, 0, 0]
]

print(solution(warehouse))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: