Solved using modified Dijkstra's algorithm in cpp beating 98 % solutions.
Intuition\nThe given solution uses a priority queue to implement a modified Dijkstra\'s algorithm for finding the minimum time to reach the bottom-right corner 
# Intuition\nThe given solution uses a priority queue to implement a modified Dijkstra\'s algorithm for finding the minimum time to reach the bottom-right corner of a grid, where the time taken to move depends on the number of steps taken.\n\n\n# Complexity\n- Time complexity:\n1. The algorithm processes each cell in the grid at most once. Since there are n * m cells in the grid, the worst-case scenario involves visiting each cell.\n2. For each cell, the algorithm checks its four possible neighbors (up, down, left, right). This results in a constant factor of 4 for each cell.\n3. The priority queue operations (insertion and extraction) take O(log(k)), where k is the number of elements in the queue. In the worst case, k can be up to n * m, leading to O(log(n * m)) for each operation.\n4. Therefore, the overall time complexity can be expressed as O((n * m) * log(n * m)).\n\n- Space complexity:\n1. The space used for the priority queue can grow up to O(n * m) in the worst case, as it may store entries for each cell.\n2. The `visited` array also takes O(n * m) space to keep track of the minimum time to reach each cell.\n3. Thus, the overall space complexity is O(n * m).\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& moveTime) {\n        int n = moveTime.size();\n        int m = moveTime[0].size();\n        priority_queue<pair<int,pair<int,pair<int,int>>>, vector<pair<int,pair<int,pair<int,int>>>> , greater<pair<int,pair<int,pair<int,int>>>>> pq;\n        vector<vector<int>> visited(n,vector<int>(m,INT_MAX));\n        visited[0][0] = 0;\n        pq.push({0,{0,{0,0}}});\n        vector<int> drow = {-1,0,1,0};\n        vector<int> dcol = {0,1,0,-1};\n        while(!pq.empty()){\n            auto [time,steps_pos] = pq.top();\n            pq.pop();\n            auto[steps , pos] = steps_pos;\n            auto[x,y] = pos;\n            if(x == n-1 && y == m-1) return time;\n            for(int i =0;i<4;i++){\n                int nx = x + drow[i];\n                int ny = y + dcol[i];\n                if(nx>=0 && nx<n && ny>=0 && ny<m){\n                    int newTime;\n                    if(steps %2 == 0){\n                        newTime = max(time,moveTime[nx][ny])+1;\n                    }\n                    else newTime = max(time,moveTime[nx][ny]) +2;\n                    if(newTime < visited[nx][ny]){\n                        visited[nx][ny] = newTime;\n                        pq.push({visited[nx][ny],{steps+1,{nx,ny}}});\n                    }\n                }\n            }\n        }\n        return -1;\n    }\n};\n```
['C++']