Video Explanation (Hindi) || Dijkstra Algorithm || Edge Case || C++
Intuition\n Describe your first thoughts on how to solve this problem. \nhttps://youtu.be/lZM00M5oljY\n\n# Approach\n Describe your approach to solving the prob
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nhttps://youtu.be/lZM00M5oljY\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe first check cell(0,1) and (1,0) if they both have value>1 we cannot find solution as we will not be able to move forwards.\n\nWe will use dijkstra algorithms to get smallest cost cell first while doing bfs to reduce time cost.\n\nThere is one edge case , if we want to move from cell(i,j) to neighbour cell and we need additional \'x\' time and \'x\' is **even** then we need \'x+1\' time .\n\nLike we are at (1,1) with time  = 2, and want to go to (1,2) with time 4 we need additional 2 sec time but we will have to give (3) sec time to get there. As 2 sec will be exhausted going to cell(1,0)and coming back to (1,1) , and we need additonal \'1\' to reach (1,2)\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(m*n log (m *n))\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(m*n)\n# Code\n```\n\nclass Solution {\npublic:\n    \n   \n    \n    int minimumTime(vector<vector<int>>& grid) {\n\n        //if cell 0,1 and cell 1,0 have >1 values then we cannot move ahed \n        //from 0,0 so no sollution\n        if(grid[0][1]>1 && grid[1][0]>1)return -1;\n\n        int n = grid.size();\n        int m = grid[0].size();\n        \n        //visited array we will process each cell atmax once\n        vector<vector<int>>vis(n,vector<int>(m));\n         \n        //using priroirty queue to give us minimum cost cell first\n        priority_queue<pair<int,pair<int,int>>>bfs;\n        bfs.push({0,{0,0}});\n         \n        \n        while(!bfs.empty()){\n            pair<int,pair<int,int>>temp = bfs.top();\n            bfs.pop();\n\n            //here x,y are coordinates of current cell\n            //tm is the total time to reach till this cell\n            int x = temp.second.first;\n            int y = temp.second.second;\n            int tm = abs(temp.first);\n            \n            //the first time we get to the last cell we return the time taken\n            //we are using Dijkstra algorithm so it will most optimal answer\n            //in first go\n            if(x == n-1 && y == m-1)return tm;\n            \n            //we dont process already visited/processed cell\n            if(vis[x][y])continue;\n\n            //marking the cell visited/processed\n            vis[x][y] = 1;\n            \n            //now we will try to go to all valid neighbours \n\n            //move up\n            if((x-1)>=0){\n                int req = grid[x-1][y] - tm;\n                //finding the required time\n\n                if(req<=1)req = max(req,1);\n                else {\n                    //if time is even we need one extra time \n                    if(req%2==0)req ++;\n                }\n                //if condition is satisfied to move to the grid cell\n                if((tm+req)>= grid[x-1][y] && vis[x-1][y] == 0){\n                   \n                    bfs.push({-(tm+req),{x-1,y}});\n                }\n                 \n            }\n            \n            //move down\n            if((x+1)<n){\n                int req = grid[x+1][y] - tm;\n                \n\n                if(req<=1)req = max(req,1);\n                else {\n                    if(req%2==0)req ++;\n                }\n                \n                if((tm+req)>= grid[x+1][y] && vis[x+1][y] == 0){\n                  \n                    bfs.push({-(tm+req),{x+1,y}});\n                } \n            }\n            \n            //move up\n            if((y-1)>=0){\n                 int req = grid[x][y-1] - tm;\n                 \n                if(req<=1)req = max(req,1);\n                else {\n                    if(req%2==0)req ++;\n                }\n                \n                if((tm+req)>= grid[x][y-1] && vis[x][y-1] == 0){\n                    \n                    bfs.push({-(tm+req),{x,y-1}});\n                }\n            }\n            \n            //move down\n            if((y+1)<m){\n                int req = grid[x][y+1] - tm;\n                \n                if(req<=1)req = max(req,1);\n                else {\n                    if(req%2==0)req ++;\n                }\n                \n                if((tm+req)>= grid[x][y+1] && vis[x][y+1] == 0){\n                    \n                    bfs.push({-(tm+req),{x,y+1}});\n                }\n            }\n       \n            \n        }\n        \n       return -1;\n      \n    }\n};\n```
['C++']