Maximize minimum of array generated by maximums of same indexed elements of two rows of a given Matrix | C ++ program for the above approach ; Function to find the maximum of minimum of array constructed from any two rows of the given matrix ; Initialize global max as INT_MIN ; Iterate through the rows ; Iterate through remaining rows ; Initialize row_min as INT_MAX ; Iterate through the column values of two rows ; Find max of two elements ; Update the row_min ; Update the global_max ; Print the global max ; Driver Code ; Given matrix mat [ ] [ ] ; Given number of rows and columns ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getMaximum ( int N , int M , vector < vector < int > > mat ) { int global_max = INT_MIN ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int row_min = INT_MAX ; for ( int k = 0 ; k < M ; k ++ ) { int m = max ( mat [ i ] [ k ] , mat [ j ] [ k ] ) ; row_min = min ( row_min , m ) ; } global_max = max ( global_max , row_min ) ; } } return global_max ; } int main ( ) { vector < vector < int > > mat = { { 5 , 0 , 3 , 1 , 2 } , { 1 , 8 , 9 , 1 , 3 } , { 1 , 2 , 3 , 4 , 5 } , { 9 , 1 , 0 , 3 , 7 } , { 2 , 3 , 0 , 6 , 3 } , { 6 , 4 , 1 , 7 , 0 } } ; int N = 6 , M = 5 ; cout << getMaximum ( N , M , mat ) ; return 0 ; }