Approach
Breadth-first search
For Path With Maximum Minimum Value, the implementation explores reachable states in layers, which is the standard shape for unweighted shortest paths and minimum-step transitions.
- Model each valid configuration as a state and each legal move as an edge.
- Seed the queue with the starting state and mark it immediately.
- Expand each state once, recording distance or reachability for unseen neighbours.
Code notes
- 35 lines of Java from the credited upstream file 1102.java.
- The implementation visibly relies on sequence storage, work queue.
- 2 loop blocks detected.
Complexity
Verify that each state and transition is processed only a bounded number of times; that determines the traversal cost.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1class Solution {2 public int maximumMinimumPath(int[][] grid) {3 record T(int i, int j, int val) {}4 final int[][] DIRS = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};5 final int m = grid.length;6 final int n = grid[0].length;7 int ans = grid[0][0];8 boolean[][] seen = new boolean[m][n];9 Queue<T> maxHeap = new PriorityQueue<>(Comparator.comparingInt(T::val).reversed()) {10 { offer(new T(0, 0, grid[0][0])); }11 };12 13 while (!maxHeap.isEmpty()) {14 final int i = maxHeap.peek().i;15 final int j = maxHeap.peek().j;16 final int val = maxHeap.poll().val;17 ans = Math.min(ans, val);18 if (i == m - 1 && j == n - 1)19 return ans;20 seen[i][j] = true;21 for (int[] dir : DIRS) {22 final int x = i + dir[0];23 final int y = j + dir[1];24 if (x < 0 || x == m || y < 0 || y == n)25 continue;26 if (seen[x][y])27 continue;28 maxHeap.offer(new T(x, y, grid[x][y]));29 }30 }31 32 throw new IllegalArgumentException();33 }34}35