Hi, everyone.

I have met a problem when designing an algorithm.

There is a MxN matrix, and not each element is filled with data. In each row, the elements who have data should be placed in different container, each column has the same requirement. That is equal to a Sudoku problem when using the number as the index of the container. Assume each row has J (J < N) data, and each column has K (K<M) data, and K<J, I think the mimum amount of container number is J. But I don't know how to put the element data into the containers.

Can it has an algorithm?

The figure has shown one example, because no more than 7 data in one row, so I think 7 container should be OK, then we should label each grid who has data with the index number (1-7), can anyone label it with an algorithm?