✅ Simple Java Solution
CODE\nJava []\nfinal int[][] dirs = {{-1,0}, {1,0}, {0,-1}, {0,1}};\npublic int minimumTime(int[][] grid) {\n\tint r = grid.length, c = grid[0].length;\n\tif(gr
## **CODE**\n```Java []\nfinal int[][] dirs = {{-1,0}, {1,0}, {0,-1}, {0,1}};\npublic int minimumTime(int[][] grid) {\n\tint r = grid.length, c = grid[0].length;\n\tif(grid[0][1] > 1 && grid[1][0] > 1) return -1;\n\n\tint[][] dp = new int[r][c];\n\tfor(int[] arr: dp) Arrays.fill(arr, -1);\n\tdp[0][0] = 0;\n\n\tQueue<int[]> bfs = new LinkedList<>();\n\tbfs.add(new int[]{0,0});\n\twhile(!bfs.isEmpty()) {\n\t\tint top[] = bfs.remove();\n\t\tfor(int dir[] : dirs) {\n\t\t\tint nr = top[0]+dir[0], nc = top[1]+dir[1];\n\t\t\tif(nr<0 || nc<0 || nr==r || nc==c) continue;\n\t\t\tint next = dp[top[0]][top[1]]+1;\n\t\t\tif(next < grid[nr][nc]) {\n\t\t\t\tint diff = grid[nr][nc]-next;\n\t\t\t\tif(diff%2 != 0) diff++;\n\t\t\t\tnext += diff;\n\t\t\t}\n\n\t\t\tif(next >= grid[nr][nc] && (dp[nr][nc] == -1 || next < dp[nr][nc])) {\n\t\t\t\tdp[nr][nc] = next;\n\t\t\t\tbfs.add(new int[]{nr,nc});\n\t\t\t}\n\t\t}\n\t}\n\treturn dp[r-1][c-1];\n}\n```
['Java']