EASY C++ SOLUTION || BEGINNER FRIENDLY || BFS||QUEUE
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 {
    struct abc{
        int x1;
        int y1;
        int x2;
        int y2;
        int count;
        int horizontal;
    };
public:
    int minimumMoves(vector<vector<int>>& grid) {
        int row = grid.size();
        int col = grid[0].size();
        map<string, int>mp;

        int answer = INT_MAX;

        queue<abc>que;
        abc ty;
        ty.x1 = 0;
        ty.y1 = 0;
        ty.x2 = 0;
        ty.y2 = 1;
        ty.count = 0;
        ty.horizontal = 1;
        que.push(ty);

        while(que.size())
        {
            abc curr = que.front();
            que.pop();
             
            string state = to_string(curr.x1) + to_string(curr.y1) + to_string(curr.x2) + to_string(curr.y2) + to_string(curr.horizontal);
            
            if(mp[state])
            continue;

            mp[state] = 1;


            if(curr.x2 == row-1 && curr.y2 == col-1 && curr.horizontal == 1)
            {
                answer = min(answer, curr.count);
                continue;
            }

            if(curr.horizontal == 1)
            {
               
                //move right
                if(curr.y2+1 < col && curr.x2 < row && grid[curr.x2][curr.y2 + 1] == 0)
                {
                    
                    abc ty;
                    ty.x1 = curr.x2;
                    ty.y1 = curr.y2;
                    ty.x2 = curr.x2;
                    ty.y2 = curr.y2+1;
                    ty.count = curr.count+1;
                    ty.horizontal = 1;
                    que.push(ty);
                }

                 //move Down
                if(curr.x1+1 < row && curr.y2 < col && curr.x2+1 < row && grid[curr.x2 + 1][curr.y2] == 0 && grid[curr.x1+1][curr.y1] == 0)
                {
                    abc ty;
                    ty.x1 = curr.x1+1;
                    ty.y1 = curr.y1;
                    ty.x2 = curr.x2 + 1;
                    ty.y2 = curr.y2;
                    ty.count = curr.count+1;
                    ty.horizontal = 1;
                    que.push(ty);
                }

                 //Roate clockwise
                if(curr.x1+1 < row && curr.x2+1 < row && grid[curr.x1 + 1][curr.y1] == 0 && grid[curr.x2+1][curr.y2] == 0)
                {
                    abc ty;
                    ty.x1 = curr.x1;
                    ty.y1 = curr.y1;
                    ty.x2 = curr.x2 + 1;
                    ty.y2 = curr.y1;
                    ty.count = curr.count+1;
                    ty.horizontal = 0;
                    que.push(ty);
                }
            }
            else if(curr.horizontal == 0)
            {
                //move right
                if(curr.y2+1 < col && curr.y1+1 < col && curr.x2 < row && grid[curr.x2][curr.y2 + 1] == 0 && grid[curr.x1][curr.y1 + 1] == 0)
                {
                    abc ty;
                    ty.x1 = curr.x1;
                    ty.y1 = curr.y1 + 1;
                    ty.x2 = curr.x2;
                    ty.y2 = curr.y2+1;
                    ty.count = curr.count+1;
                    ty.horizontal = 0;
                    que.push(ty);
                }

                 //move Down
                if(curr.y1 < col && curr.x2+1 < row && grid[curr.x2 + 1][curr.y2] == 0)
                {
                    abc ty;
                    ty.x1 = curr.x2;
                    ty.y1 = curr.y1;
                    ty.x2 = curr.x2 + 1;
                    ty.y2 = curr.y2;
                    ty.count = curr.count+1;
                    ty.horizontal = 0;
                    que.push(ty);
                }

                 //Roate anti-clockwise
                if(curr.y2+1 < col && curr.y1+1 < col && curr.x2-1 >=0 && curr.x1 >= 0 && grid[curr.x2][curr.y2 + 1] == 0 && grid[curr.x2-1][curr.y2+1] == 0)
                {
                    abc ty;
                    ty.x1 = curr.x1;
                    ty.y1 = curr.y1;
                    ty.x2 = curr.x1;
                    ty.y2 = curr.y1 + 1;
                    ty.count = curr.count+1;
                    ty.horizontal = 1;
                    que.push(ty);
                }
            }


        }

        if(answer == INT_MAX)
        return -1;
    
        return answer;    
    }
};
```
['Breadth-First Search', 'Queue', 'C++']