Simple Dijkstra Solution C++
Simple dijkstra Algorithm C++\n\n\nclass Solution {\npublic:\n    int minimumMoves(vector<vector<int>>& grid) {\n        int n=grid.size();\n        map<pair<pa
Simple dijkstra Algorithm C++\n\n```\nclass Solution {\npublic:\n    int minimumMoves(vector<vector<int>>& grid) {\n        int n=grid.size();\n        map<pair<pair<int,int>,pair<int,int>>,int>vis;            //marks all visited states\n        set<pair<int,pair<pair<int,int>,pair<int,int>>>>q;              // works as priority queue first element is cost \n        q.insert({0,{{0,0},{0,1}}});\n        while(!q.empty()){\n            auto it=q.begin();\n            int x1=it->second.first.first;\n            int y1=it->second.first.second;\n            int x2=it->second.second.first;\n            int y2=it->second.second.second;\n            int cost=it->first;\n            if(x1==n-1 && y1==n-2 && x2==n-1 && y2==n-1){                 //goal found\n                return cost;\n            }\n            if(vis[{{x1,y1},{x2,y2}}]==0){   //check if already visited\n                if(y1+1<n && y2+1<n && grid[x1][y1+1]!=1 && grid[x2][y2+1]!=1){        //can go down\n                    q.insert({cost+1,{{x1,y1+1},{x2,y2+1}}});\n                }\n                if(x1+1<n && x2+1<n && grid[x1+1][y1]!=1 && grid[x2+1][y2]!=1){        //can go right\n                    q.insert({cost+1,{{x1+1,y1},{x2+1,y2}}});\n                }\n                if(x1==x2 && x1+1<n && y1+1<n && x2+1<n && y2-1>=0 && grid[x2+1][y2-1]!=1 && grid[x1+1][y1+1]!=1){    //can rotate clockwise\n                    q.insert({cost+1,{{x1,y1},{x2+1,y2-1}}});\n                }\n                if(y1==y2 && x1+1<n && y1+1<n && x2-1>=0 && y2+1<n && grid[x2-1][y2+1]!=1 && grid[x1+1][y1+1]!=1){    //can rotate anticlockwise\n                    q.insert({cost+1,{{x1,y1},{x2-1,y2+1}}});\n                }\n                vis[{{x1,y1},{x2,y2}}]=1;          //mark state as visited\n            }\n            q.erase(it);\n        }\n        return -1;\n    }\n};\n```
[]