Very simple solution using BFS in C#
Intuition\n  The problem is really easy if you can walk yourself through example test case 1 and example test case 2. Just follow how you can travel right, righ
# Intuition\n  The problem is really easy if you can walk yourself through example test case 1 and example test case 2. Just follow how you can travel right, right, counter clockwise like the way example explains, and you will understand the problem.\n\n# Approach\n Breadth first search\n\n# Complexity\n- Time complexity:\n  O(NxM)\n\n- Space complexity:\n  O(NxM)\n\n# Code\n```\npublic class Solution {\n    public int MinimumMoves(int[][] grid) {\n        //the problem is easy if we can understand how\n        //the snakes position changes in each//\n        //right, down, and rotate moves\n        int n = grid.Length;\n        Queue<(int r1, int c1, int r2, int c2, int move)> q = \n        new Queue<(int,int,int,int,int)>();\n        q.Enqueue((0,0,0,1,0));\n        HashSet<string> map = new HashSet<string>();\n        while(q.Count > 0){\n            int r1 = q.Peek().r1;\n            int c1 = q.Peek().c1;\n            int r2 = q.Peek().r2;\n            int c2 = q.Peek().c2;\n            int move = q.Peek().move;\n            if(r1 == n-1 && c1 == n-2 && r2 ==n-1 && c2 == n-1) {\n                return move;\n            }\n\n            q.Dequeue();\n            string key = "R1C1-"+r1+"-"+c1+"-R2C2-"+r2+"-"+c2;\n            if(map.Contains(key)) continue;\n            map.Add(key);\n            //when snake is flat or in right position\n            if(r1 == r2){\n                if(c2+1 < n && c1+1 < n &&  grid[r1][c1+1]== 0 &&grid[r2][c2+1] == 0){\n                    q.Enqueue((r1,c1+1,r2, c2+1,move+1));\n                }\n                //check down position\n                if(r1+1 < n && r2+1 < n && grid[r1+1][c1] == 0 && grid[r2+1][c2] == 0){\n                    q.Enqueue((r1+1, c1, r2+1, c2, move+1));\n                    //we can also do rotate clockwise - intuition careful observation from example 1 test case\n                    q.Enqueue((r1, c1, r2+1, c1, move+1));\n                }\n            }\n            //when snake is in vertical position\n            if(c1 == c2){\n                if(c2+1 < n && c1+1 < n &&  grid[r1][c1+1]== 0 && grid[r2][c2+1] == 0){\n                    q.Enqueue((r1,c1+1,r2, c2+1,move+1));\n                    //this is rotate counter clockwise\n                    q.Enqueue((r1,c1, r1, c2+1,move+1));\n                }\n                //check down position\n                if(r1+1 < n && r2+1 < n && grid[r1+1][c1] == 0 && grid[r2+1][c2] == 0){\n                    q.Enqueue((r1+1, c1, r2+1, c2, move+1));\n                }                \n            }\n        }\n        return -1;\n    }\n}\n```
['Breadth-First Search', 'C#']