Talentd
FleetCode

1102. Path With Maximum Minimum Value

Medium54.6% acceptance3 companiesPremium elsewhere, free here

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.

Example 1:

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

Example 2:

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

Example 3:

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

Asked at 3 companies

Hints open one at a time

Hint 1
What if we sort each cell of the matrix by the value?
Hint 2
Don't include small values in your path if you can only include large values.
Hint 3
Let's keep adding a possible cell to use in the path incrementally with decreasing values.
Hint 4
If the start and end cells are connected then we don't need to add more cells.
Hint 5
Use union-find data structure to check connectivity and return as answer the value of the given cell that makes start and end cells connected.
11:35
Still stuck?Read 2 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
[[5,4,5],[1,2,6],[7,4,6]]
Input
[[2,2,1,2,2,2],[1,2,2,2,1,2]]
Input
[[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]]
Your code is saved on this device.Solution