Priority Grid: Minimize the Maximum Value

You are curating a priority board. Each square of an m x n grid contains an original priority. Replace every priority with a positive integer rank, producing a new grid of the same shape.

The replacement must obey three rules:

  • If two squares share a row or a column, their original priorities must keep their order. A smaller priority receives a smaller rank, and an equal priority receives the same rank.
  • Ranks are positive integers.
  • Among all valid replacement grids, minimize the largest rank used.

Return one replacement grid with the smallest possible maximum rank. If several grids are possible, any one is accepted.

Think of equal priorities as arriving together. Sorting the priorities tells us when a new ranking layer becomes available, while rows and columns share ranking history.

Examples
Input: [[5]]
Output: [[1]]
Hints

Priority Grid: Minimize the Maximum Value

You are curating a priority board. Each square of an `m x n` grid contains an original priority. Replace every priority with a positive integer rank, producing a new grid of the same shape.