Minimize Maximum Value in a Grid - Problem
You are given an m x n integer matrix grid containing distinct positive integers. Your task is to replace each integer in the matrix with a positive integer while satisfying these crucial conditions:
- Preserve relative order: The relative order of every two elements that are in the same row or column must stay the same after replacements
- Minimize maximum: The maximum number in the matrix after replacements should be as small as possible
The relative order condition means: if grid[r1][c1] > grid[r2][c2] where either r1 == r2 or c1 == c2, then this inequality must remain true after replacements.
Example: For matrix [[2, 4, 5], [7, 3, 9]], valid replacements include [[1, 2, 3], [2, 1, 4]] or [[1, 2, 3], [3, 1, 4]].
Return the resulting matrix. If multiple valid answers exist, return any of them.
Input & Output
Constraints
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code