JAVA solution | using Heap
The solution below is the extension of the simplified version of this problem \n\nhttps://leetcode.com/problems/find-minimum-time-to-reach-last-room-i/discuss/6
The solution below is the extension of the simplified version of this problem \n\nhttps://leetcode.com/problems/find-minimum-time-to-reach-last-room-i/discuss/6003977/JAVA-Solution-or-using-heap\n\n```\npublic int minTimeToReach(int[][] moveTime) {\n        int m = moveTime.length, n = moveTime[0].length;\n        \n        int[][] moves = {{0,1},{0,-1},{1,0},{-1,0}};\n        \n        PriorityQueue<int[]> pq = new PriorityQueue<>((a,b) -> a[0] - b[0]);\n        \n        Integer[][] minTime = new Integer[m][n];\n        \n        // 0: min time sofar\n        // 1: i co-ordinate \n        // 2: j co-ordinate \n        // 3: 1 - represnets odd position, 0 - represents even position \n        pq.offer(new int[]{0,0,0,0});\n        \n        while(!pq.isEmpty()){\n            int[] top = pq.poll();\n            \n            if(top[1] == m-1 && top[2] == n-1){\n                return top[0];\n            }\n            \n            if(minTime[top[1]][top[2]] != null && minTime[top[1]][top[2]] < top[0]){\n                continue;\n            }\n            \n            for(int[] move : moves){\n                int x = move[0] + top[1], y = move[1] + top[2];\n                \n                if(x < 0 || x >= m || y < 0 || y >= n){\n                    continue;\n                }\n                \n                // if cur is odd position then cost is 2 otherwise the cost is 1\n                int nextMoveCost = Math.max(moveTime[x][y], top[0]) + (top[3] == 1 ? 2 : 1);\n                \n                if(minTime[x][y] == null || minTime[x][y] > nextMoveCost){\n                    minTime[x][y] = nextMoveCost;\n                    \n                    // if the current position is even then next position will be odd and vice versa\n                    pq.offer(new int[]{nextMoveCost, x, y, (top[3] == 1 ? 0 : 1)});\n                }\n            }\n        }\n        \n        return -1;\n    }\n\n```
['Heap (Priority Queue)', 'Java']