Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- static int[][] MOVES = new int[][]{
- {0, -1},
- {0, 1},
- {-1, 0},
- {1, 0},
- };
- public int maximumMinimumPath(int[][] A) {
- return solve(0, 0, A, new boolean[A.length][A[0].length], A[0][0], new HashMap<>());
- }
- int solve(int i, int j, int[][] A, boolean[][] visited, int minSofar, Map<String, Integer> memo) {
- if(i == A.length - 1 && j == A[0].length - 1) {
- return minSofar;
- }
- String key = i + "," + j;
- if(memo.containsKey(key)) {
- return Math.min(minSofar, memo.get(key));
- }
- int max = 0;
- for (int[] move : MOVES) {
- int x = i + move[0];
- int y = j + move[1];
- if (x >= 0 && x < A.length && y >= 0 && y < A[0].length && !visited[x][y]) {
- visited[x][y] = true;
- max = Math.max(max, solve(x,y, A, visited, Math.min(minSofar, A[x][y]), memo));
- visited[x][y] = false;
- }
- }
- memo.put(key, max);
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement