Maximize the minimum cell value on a grid path from top-left to bottom-right

Quick Overview

Given an integer grid, find a path from the top-left cell to the bottom-right cell, moving up, down, left or right, whose smallest cell value is as large as possible, and return that value. It tests bottleneck path reasoning on a grid and choosing a search order that settles each cell correctly the first time.

Maximize the minimum cell value on a grid path from top-left to bottom-right

Company: Dropbox

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given an `m x n` integer matrix `grid`, return the maximum score of a path that starts at `(0, 0)` and ends at `(m - 1, n - 1)`. The score of a path is the minimum value in that path. A path can move in 4 directions: up, down, left, and right. ### Function Signature ```python def maximum_minimum_path(grid: list[list[int]]) -> int: ``` ### Rules - A path is a sequence of cells where each step moves to an adjacent cell up, down, left or right, staying inside the grid. - The score counts every cell on the path, including `(0, 0)` and `(m - 1, n - 1)`. - Return the largest score over all such paths. When `m == n == 1`, the only path is the single cell and the answer is its value. ### Constraints - `m == grid.length` - `n == grid[i].length` - `1 <= m, n <= 100` - `0 <= grid[i][j] <= 10^9` ### Examples ```text Input: grid = [[5,4,5],[1,2,6],[7,4,6]] Output: 4 ``` The path `5 -> 4 -> 5 -> 6 -> 6` along the top row and down the right column has minimum 4. No path can do better: the start's only neighbors hold 4 and 1, so every path contains a value of 4 or less. ```text Input: grid = [[2,2,1,2,2,2],[1,2,2,2,1,2]] Output: 2 ``` The path `(0,0) -> (0,1) -> (1,1) -> (1,2) -> (1,3) -> (0,3) -> (0,4) -> (0,5) -> (1,5)` steps around both 1s and visits only cells with value 2. The start itself is 2, so no path can score higher. ```text Input: grid = [[6,7,8],[1,2,9],[9,5,9],[7,0,3],[8,9,9]] Output: 5 ``` Going straight down the right column passes the 3 at `(3, 2)` and scores 3. Turning left along row 2 through the 5 at `(2, 1)`, then down the left column and across the bottom row, scores 5. A score above 5 is impossible, because the cells above 5 split into two groups that do not touch: one holds the start and the other holds the end.

Overview: Given an integer grid, find a path from the top-left cell to the bottom-right cell, moving up, down, left or right, whose smallest cell value is as large as possible, and return that value. It tests bottleneck path reasoning on a grid and choosing a search order that settles each cell correctly the first time.

Dropbox logo
Dropbox
Nov 25, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Given an m x n integer matrix grid, return the maximum score of a path that starts at (0, 0) and ends at (m - 1, n - 1).

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

A path can move in 4 directions: up, down, left, and right.

Function Signature

def maximum_minimum_path(grid: list[list[int]]) -> int:

Rules

  • A path is a sequence of cells where each step moves to an adjacent cell up, down, left or right, staying inside the grid.
  • The score counts every cell on the path, including (0, 0) and (m - 1, n - 1) .
  • Return the largest score over all such paths. When m == n == 1 , the only path is the single cell and the answer is its value.

Constraints

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

Examples

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

The path 5 -> 4 -> 5 -> 6 -> 6 along the top row and down the right column has minimum 4. No path can do better: the start's only neighbors hold 4 and 1, so every path contains a value of 4 or less.

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

The path (0,0) -> (0,1) -> (1,1) -> (1,2) -> (1,3) -> (0,3) -> (0,4) -> (0,5) -> (1,5) steps around both 1s and visits only cells with value 2. The start itself is 2, so no path can score higher.

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

Going straight down the right column passes the 3 at (3, 2) and scores 3. Turning left along row 2 through the 5 at (2, 1), then down the left column and across the bottom row, scores 5. A score above 5 is impossible, because the cells above 5 split into two groups that do not touch: one holds the start and the other holds the end.