Can someone explain the 'trick' to this question, because I am just not getting it. What's the connection between the minimum of the row/column length and the number of operations?
I wrote code that creates the matrix and applies the operations to it, and tracks the max integer and how often it is seen as it goes along- that produces the correct answer. But it runs out memory in some of the test cases, so that naive approach won't work. But I can't make the logical jump to this shortcut method!