> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Path With Maximum Minimum Value

> Tested Python solution for LeetCode 1102 with 12 pytest cases. Generate a practice environment with lcpy.

LeetCode 1102, [Medium](/catalog/medium). Topics: [Array](/catalog/topics/array), [Binary Search](/catalog/topics/binary-search), [Depth-First Search](/catalog/topics/depth-first-search), [Breadth-First Search](/catalog/topics/breadth-first-search), [Union Find](/catalog/topics/union-find), [Heap (Priority Queue)](/catalog/topics/heap-priority-queue), [Matrix](/catalog/topics/matrix). [View on LeetCode](https://leetcode.com/problems/path-with-maximum-minimum-value/description/).

Generate this problem as a practice environment: tested reference solution, 12 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 1102   # by problem number
lcpy gen -s path_with_maximum_minimum_value   # by problem name
```

## Problem

Given an `m x n` integer matrix `grid`, return *the maximum **score** of a path starting at* `(0, 0)` *and ending at* `(m - 1, n - 1)` moving in the **4** cardinal directions.

The **score** of a path is the minimum value in that path.

* For example, the score of the path `8 → 4 → 5 → 9` is `4`.

### Examples

```
Input: grid = [[5,4,5],[1,2,6],[7,4,6]]
Output: 4
Explanation: The path with the maximum score is highlighted in yellow.
```

```
Input: grid = [[2,2,1,2,2,2],[1,2,2,2,1,2]]
Output: 2
```

```
Input: grid = [[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]]
Output: 3
```

### Constraints

* m == grid.length
* n == grid\[i].length
* 1 \<= m, n \<= 100
* 0 \<= grid\[i]\[j] \<= 10^9

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/path_with_maximum_minimum_value/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/path_with_maximum_minimum_value/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import heapq


class Solution:
    # Time: O(m * n * log(m * n))
    # Space: O(m * n)
    def maximum_minimum_path(self, grid: list[list[int]]) -> int:
        m, n = len(grid), len(grid[0])
        heap = [(-grid[0][0], 0, 0)]
        seen = [[False] * n for _ in range(m)]
        while heap:
            neg_v, i, j = heapq.heappop(heap)
            if seen[i][j]:
                continue
            seen[i][j] = True
            if (i, j) == (m - 1, n - 1):
                return -neg_v
            for a, b in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                x, y = i + a, j + b
                if 0 <= x < m and 0 <= y < n and not seen[x][y]:
                    heapq.heappush(heap, (-min(-neg_v, grid[x][y]), x, y))
        raise AssertionError
```

## Complexity

| Time | Space |
| - | - |
| O(m \* n \* log(m \* n)) | O(m \* n) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.