Comments

Yeah i got it now.

We can only decrement aij once.

We have to output the minimum maximum value right?

Yeah.

Suppose the max element in matrix is 9 and rest of the elements are 5.

5 5 5

9 5 5

Now we can choose r=2 and c=1 and ans will be 7 but according to algorithm we get 8. if maxx=largest element in matrix and secondMaxx= 2nd largest then, I tried writing two diff cases for when maxx-secondMaxx>1 and maxx-secondMaxx==1.

Even in the first test case

1 1

1

The answer should be -1 right? After choosing r=1 and c=1. Can anyone please explain where I have gone wrong?