Shortest Path - BFS
Approach - We will use a priority queue to store the cells visited and also the minimum time required to get to the cell and mark the cell visited and from each
Approach - We will use a priority queue to store the cells visited and also the minimum time required to get to the cell and mark the cell visited and from each cell we will try to move in all the four directions whenever possible.\nPoints to note - \n\t1- We will use min priority queue with time as the criteria to keep our cells in increasing order.\n\t2-At any cell if we cannot make move due to the higher value of time required to get to that cell then there will be a cell from where we reach to current cell with which we can make some to and fro motions to satisfy the given condition.\n```\nclass Solution {\npublic:\n    \n    int minimumTime(vector<vector<int>>& grid) {\n        int m=grid.size(), n=grid[0].size();\n        if(grid[0][1]!=1 && grid[1][0]!=1 && grid[0][1]!=0 && grid[1][0]!=0) return -1;\n        vector<vector<int>> vis(1002,vector<int>(1001,0));\n        priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;\n        vector<int> dx={1,0,-1,0};\n        vector<int> dy={0,1,0,-1};\n        \n        pq.push({0,0,0});\n        while(pq.size()>0){\n            \n            auto curr=pq.top();\n            pq.pop();\n            int x=curr[1], y=curr[2], cost=curr[0];\n            cout<<cost<<" ";\n            if(x==m-1 && y==n-1) return cost;\n            for(int i=0;i<4;i++){\n                if(x+dx[i]<m && y+dy[i]<n  && x+dx[i]>=0 && y+dy[i]>=0  && (vis[x+dx[i]][y+dy[i]]==0)){\n                    vis[x+dx[i]][y+dy[i]]=1;\n                     int val=0;\n                    if(grid[x+dx[i]][y+dy[i]]<=cost){\n                        val=cost;\n                    }\n                    else{\n                        int z=(grid[x+dx[i]][y+dy[i]]-cost)/2;\n                        val=cost+2*abs(z);\n                    }\n                   pq.push({val+1, x+dx[i], y+dy[i]});\n                }\n            }\n        }\n        return -2;\n    }\n};\n```
['Breadth-First Search', 'C']