# 1102. Path With Maximum Minimum Value

![](/files/-MdgkO5nsRHuielbOCwu)

![](/files/-MdgkR2ZOao_G69wxoPs)

```
1102. Path With Maximum Minimum Value

time: O(m*n * log(m*n))
space: O(m*n) // visited matrix

use Dijkstra's algo
```

```java
class Solution {
    public int maximumMinimumPath(int[][] grid) {
        if (grid == null || grid.length > 0 && grid[0].length == 0) return 0;
        int m = grid.length;
        int n = grid[0].length;
        boolean visited[][] = new boolean[m][n];
        
        PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> b[0] - a[0]);
        pq.offer(new int[]{grid[0][0], 0, 0});
        visited[0][0] = true;
        int maxScore = grid[0][0];
        
        int dir[][] = new int[][]{{0,1}, {1,0}, {-1, 0}, {0,-1}};
        while (!pq.isEmpty()) {
            int cell[] = pq.poll();
            int score = cell[0];
            int row = cell[1];
            int col = cell[2];
            maxScore = Math.min(maxScore, score);
            if (row == m - 1 && col == n -1) {
                return maxScore;
            }
            for (int d[] : dir) {
                int newRow = row + d[0];
                int newCol = col + d[1];
                if (newRow >= 0 && newRow < m && newCol >= 0 && newCol < n && !visited[newRow][newCol]) {
                    pq.offer(new int[]{grid[newRow][newCol], newRow, newCol});
                    visited[newRow][newCol] = true;
                }
            }
        }
        return maxScore;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://timmybeeflin.gitbook.io/cracking-leetcode/path-related/1102.-path-with-maximum-minimum-value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
