C# Solution
\npublic class Solution \n{\n    public int MinimumMoves(int[][] grid) \n    {\n        int r = grid.Length, c = grid[0].Length;\n        var queue = new Queue<
```\npublic class Solution \n{\n    public int MinimumMoves(int[][] grid) \n    {\n        int r = grid.Length, c = grid[0].Length;\n        var queue = new Queue<int[]>();\n        queue.Enqueue(new int[] {0, 0, 0});\n        var visited = new bool[r,c,2];\n        visited[0, 0, 0] = true;\n        int depth = 0;\n        while(queue.Count != 0)\n        {\n            var count = queue.Count();\n            while(count-- != 0)\n            {\n                var curr = queue.Dequeue();\n                int x = curr[0], y = curr[1], dir = curr[2];\n                if((x == r - 1 && y == c - 2 && dir == 0))\n                    return depth;\n                List<int[]> next = new List<int[]>();\n                if(dir == 0)\n                {\n                    if(y + 2 < c && grid[x][y + 2] == 0)\n                        next.Add(new[] {x, y + 1, 0});\n                    if(x + 1 < r && grid[x + 1][y] == 0 && grid[x + 1][y + 1] == 0)\n                    {\n                        next.Add(new[] {x, y, 1});\n                        next.Add(new[] {x + 1, y, 0});\n                    }\n                }\n                else\n                {\n                    if(x + 2 < r && grid[x + 2][y] == 0)\n                        next.Add(new[] {x + 1, y, 1});\n                    if(y + 1 < c && grid[x][y + 1] == 0 && grid[x + 1][y + 1] == 0)\n                    {\n                        next.Add(new[] {x, y, 0});\n                        next.Add(new[] {x, y + 1, 1});\n                    }\n                }\n                    \n                foreach(var n in next)\n                {\n                    if(!visited[n[0], n[1], n[2]])\n                    {\n                        visited[n[0], n[1], n[2]] = true;\n                        queue.Enqueue(n);\n                    }\n                }\n            }\n            \n            depth++;\n        }\n        \n        return -1;\n    }\n}\n```
[]