[Python3] BFS - Do What They Said - Simple Solutionb
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def minimumMoves(self, grid: List[List[int]]) -> int:\n        n = len(grid)\n        dq = collections.deque([((0, 0, 0, 1), 0)])\n        visited = set()\n        while dq:\n            (tail_r, tail_c, head_r, head_c), step = dq.popleft()\n            if (tail_r, tail_c, head_r, head_c) in visited: continue\n            if (tail_r, tail_c) == (n - 1, n - 2) and (head_r, head_c) == (n - 1, n - 1): return step\n            visited.add((tail_r, tail_c, head_r, head_c))\n            if head_c + 1 < n and grid[tail_r][tail_c + 1] != 1 and grid[head_r][head_c + 1] != 1: \n                dq.append(((tail_r, tail_c + 1, head_r, head_c + 1), step + 1)) # move right\n            if head_r + 1 < n and grid[tail_r + 1][tail_c] != 1 and grid[head_r + 1][head_c] != 1: \n                dq.append(((tail_r + 1, tail_c, head_r + 1, head_c), step + 1)) # move down\n            if tail_r == head_r and head_r + 1 < n and grid[tail_r + 1][tail_c] != 1 and grid[head_r + 1][head_c] != 1: \n                dq.append(((tail_r, tail_c, head_r + 1, head_c - 1), step + 1)) # rotate clockwise\n            if tail_c == head_c and head_c + 1 < n and grid[tail_r][tail_c + 1] != 1 and grid[head_r][head_c + 1] != 1: \n                dq.append(((tail_r, tail_c, head_r - 1, head_c + 1), step + 1)) # rotate counter clockwise\n        return -1\n```
['Hash Table', 'Breadth-First Search', 'Python3']