# Max in every column and Min in every row

I have a matrix such as this

mat ={{6, 5},{5, 4}}


and I want to find the maximum in every column and minimum in every row. After that I have to get the same number of both. I write this

Max /@ Transpose[mat]


and

Min /@ mat


The results are {6,5} and {5,4}. However I am not sure how I can find that 5 is the same for both. And also it will be good to have all commands to be in one cycle.

mat = {{6, 5}, {5, 4}};


Those row/column indices i,j for which the minimal row element is the same as the maximal column element is:

Tuples[{Min /@ mat, Max /@ Transpose[mat]}] //
Position[ArrayReshape[Differences[#, {0, 1}][[All, 1]], Dimensions[mat]], 0] &


{{1, 2}}

• This code works for row 1 but when I wrote this matt = {{5, 4}, {6, 5}}; the answer is {{1, 4}} but have to be row 2 column 2 . Commented Nov 7, 2018 at 18:16
• @M.Alexis I can't reproduce that. Try wrapping With[{mat = matt}, ....] around the code. Commented Nov 7, 2018 at 18:19
• I also tried the solution from @MeMyselfI and it works fine for both matrices, as well as something along the lines of Table[RandomInteger[{0, 10}], {i, 4}, {j, 4}] (it might take a bigger matrix or some repetitions to get something other than a blank table). For a way that is faster than Position see here Commented Nov 8, 2018 at 10:53