1210. Minimum Moves to Reach Target with Rotations
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int minimumMoves(vector<vector<int>>& grid) {
        int n = grid.size();
        vector<vector<vector<bool>>> visitedStatus(2, vector<vector<bool>>(n, vector<bool>(n, false)));
        queue<array<int, 4>> moveQueue;
        moveQueue.push({0, 0, 1, 0});
        visitedStatus[0][0][1] = true;

        while (!moveQueue.empty()) {
            auto [currentState, currentRow, currentCol, moveCount] = moveQueue.front();
            moveQueue.pop();

            if (currentState == 0 && currentRow == n - 1 && currentCol == n - 1) return moveCount;

            if (currentState == 0) {
                if (currentCol + 1 < n && grid[currentRow][currentCol + 1] == 0 && !visitedStatus[0][currentRow][currentCol + 1]) {
                    visitedStatus[0][currentRow][currentCol + 1] = true;
                    moveQueue.push({0, currentRow, currentCol + 1, moveCount + 1});
                }
                if (currentRow + 1 < n && grid[currentRow + 1][currentCol] == 0 && grid[currentRow + 1][currentCol - 1] == 0) {
                    if (!visitedStatus[0][currentRow + 1][currentCol]) {
                        visitedStatus[0][currentRow + 1][currentCol] = true;
                        moveQueue.push({0, currentRow + 1, currentCol, moveCount + 1});
                    }
                    if (!visitedStatus[1][currentRow + 1][currentCol - 1]) {
                        visitedStatus[1][currentRow + 1][currentCol - 1] = true;
                        moveQueue.push({1, currentRow + 1, currentCol - 1, moveCount + 1});
                    }
                }
            } else {
                if (currentRow + 1 < n && grid[currentRow + 1][currentCol] == 0 && !visitedStatus[1][currentRow + 1][currentCol]) {
                    visitedStatus[1][currentRow + 1][currentCol] = true;
                    moveQueue.push({1, currentRow + 1, currentCol, moveCount + 1});
                }
                if (currentCol + 1 < n && grid[currentRow][currentCol + 1] == 0 && grid[currentRow - 1][currentCol + 1] == 0) {
                    if (!visitedStatus[1][currentRow][currentCol + 1]) {
                        visitedStatus[1][currentRow][currentCol + 1] = true;
                        moveQueue.push({1, currentRow, currentCol + 1, moveCount + 1});
                    }
                    if (!visitedStatus[0][currentRow - 1][currentCol + 1]) {
                        visitedStatus[0][currentRow - 1][currentCol + 1] = true;
                        moveQueue.push({0, currentRow - 1, currentCol + 1, moveCount + 1});
                    }
                }
            }
        }
        return -1;
    }
};

```
['C++']