BFS || Using Direction Array || Clean Code
\n\nclass Solution:\n    def minimumMoves(self, grid: List[List[int]]) -> int:\n        n = len(grid)\n        queue = deque([[(0, 0), (0, 1), 0]])\n        vis
```\n\nclass Solution:\n    def minimumMoves(self, grid: List[List[int]]) -> int:\n        n = len(grid)\n        queue = deque([[(0, 0), (0, 1), 0]])\n        visited = {((0, 0), (0, 1))}\n        directions = [[(0, 1), (0, 1)], \n                      [(1, 0), (1, 0)], \n                      [(0, 0), (1, -1)], \n                      [(0, 0), (-1, 1)]]\n\n        def validate(i1, j1, i2, j2, index):\n            if not (0 <= i1 < n and 0 <= j1 < n and 0 <= i2 < n and 0 <= j2 < n):\n                return False\n            \n            if grid[i1][j1] != 0 or grid[i2][j2] != 0:\n                return False\n            \n            if index >= 2:  # Edge Case 1\n                if grid[i1+1][j1+1] == 1:\n                    return False\n            \n            return True\n\n        \n        while queue:\n            \n            c1, c2, step = queue.popleft()\n            i1, j1 = c1\n            i2, j2 = c2\n\n            if i1 == n-1 and j1 == n-2 and i2 == n-1 and j2 == n-1:\n                return step\n\n            for index in range(len(directions)):\n                if index == 2:\n                    if i1 != i2:\n                        continue\n                if index == 3:\n                    if j1 != j2:\n                        continue\n                c1_drn, c2_drn = directions[index]\n                i1_drn, j1_drn = c1_drn\n                i2_drn, j2_drn = c2_drn\n\n                new_i1 = i1+i1_drn\n                new_j1 = j1+j1_drn\n\n                new_i2 = i2+i2_drn\n                new_j2 = j2+j2_drn\n                if validate(new_i1, new_j1, new_i2, new_j2, index) and ((new_i1, new_j1), (new_i2, new_j2)) not in visited:\n                    visited.add(((new_i1, new_j1), (new_i2, new_j2)))\n                    # print(step, ((new_i1, new_j1), (new_i2, new_j2), step+1))\n                    queue.append(((new_i1, new_j1), (new_i2, new_j2), step+1))\n\n        return -1\n\n```
['Dynamic Programming', 'Breadth-First Search', 'Python']