Beats 100%(Easy to understand)
Intuition\nSame as Previos question just apply step logic\n# Approach\nMaintain a third variable for step and toggle it between 1 and 2 which can be done as 3-s
# Intuition\nSame as Previos question just apply step logic\n# Approach\nMaintain a third variable for step and toggle it between 1 and 2 which can be done as 3-step\n\n# Complexity\n- Time complexity:\nO(N\u2217M\u2217Log(N+M))\n\n- Space complexity:\nO(N\u2217M)\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        vector<vector<int>> minTime(n, vector<int>(m, INT_MAX));\n        \n        \n        priority_queue<tuple<int, int, int, int>, vector<tuple<int, int, int, int>>, greater<>> pq;\n        \n        pq.push({0, 0, 0, 1}); \n        minTime[0][0] = 0;\n\n        vector<pair<int, int>> directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n        while (!pq.empty()) {\n            auto [currTime, x, y, step] = pq.top();\n            pq.pop();\n\n            if (x == n - 1 && y == m - 1) return currTime;\n\n            for (auto& dir : directions) {\n                int nx = x + dir.first;\n                int ny = y + dir.second;\n\n                if (nx < 0 || ny < 0 || nx >= n || ny >= m) continue;\n\n                // int waitTime = max(0, moveTime[nx][ny] - currTime);\n                int nextTime = max(moveTime[nx][ny] , currTime)+step;\n                int nextStep = 3 - step;\n\n                if (nextTime < minTime[nx][ny]) {\n                    minTime[nx][ny] = nextTime;\n                    pq.push({nextTime, nx, ny, nextStep});\n                }\n            }\n        }\n\n        return -1; \n    }\n};\n\n```
['C++']