grid of distinct positive integers. Replace every number with a positive integer so that the order inside each row and each column is kept: if a number was larger than another number of the same row or column, it must still be larger after the replacement.
The new values must be as small as possible: a cell gets 1 if its number is the smallest in both its row and its column, and otherwise one more than the largest new value among the smaller numbers of its row and its column. This replacement is unique, and it also makes the largest number in the table as small as it can be.
Return the resulting table.grid=[[4, 9], [7, 2]] → [[1, 2], [2, 1]]
2 and 4 are the smallest in their rows and columns, so both get 1. 7 is larger than 2 in its row and larger than 4 in its column, so it gets 2; the same goes for 9.
grid=[[5, 1, 8]] → [[2, 1, 3]]
In a single row the order 1 < 5 < 8 becomes 1 < 2 < 3.
grid=[[3, 6], [10, 4], [2, 7]] → [[2, 3], [3, 1], [1, 4]]
grid are distinctgrid=[[4, 9], [7, 2]]
[[1, 2], [2, 1]]
Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.