498. Path With Maximum Minimum Value

Given an m*n integer matrix grid, your task is to find a path from the top-left corner (0,0) to the bottom-right corner (m-1, n-1) that maximizes the minimum value along the path.

You can move in the four cardinal directions (north, south, east, west). The score of a path is defined as the minimum value in that path.

Your goal is to return the maximum score possible.

Example 1:

Input: grid = [[5,4,5],[1,2,6],[7,4,6]]

Output: 4

Explanation: The best path from (0,0) to (2,2) is (5 → 4 → 5 → 6 → 6), where the minimum value along the path is 4.

Example 2:

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

Output: 2

Explanation: The best path from (0,0) to (1,5) is (2 → 2 → 2 → 2 → 2 → 2), where the minimum value along the path is 2.

Now Your Turn!

Pick the correct output for the given input

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]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 100
  • 0 <= grid[i][j] <= 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int maxMinPath(vector<vector<int>>& grid) {
//your code goes here
}
};
Test Case

Input:

Grid