Ctrl K

Fill Blanks With the Column Maximum

Easy
You get an m × n table of scores grid. A value of -1 marks a blank. Replace every blank with the largest value in its column and return the resulting table. Every column is guaranteed to contain at least one non-negative value.
Example 1
grid=[[5, -1], [-1, 3], [2, 7]] → [[5, 7], [5, 3], [2, 7]]

Column 0 has maximum 5, which fills the blank in row 1; column 1 has maximum 7, which fills the blank in row 0.

Example 2
grid=[[0, 4], [0, 4]] → [[0, 4], [0, 4]]

There are no blanks, so the grid stays the same.

Constraints
  • 2 ≤ m, n ≤ 50
  • -1 ≤ grid[i][j] ≤ 100
  • Every column has at least one value ≥ 0
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCrossword That Reads Both Ways EasyIsland Coastline Length EasyRepack the Tray EasyBlur the Pixels EasyPaint Bucket Tool Easy
loading Python…
Input
grid=[[5, -1], [-1, 3], [2, 7]]
Expected
[[5, 7], [5, 3], [2, 7]]

Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.