Maximize modulus by replacing adjacent pairs with their modulus for any permutation of given Array | C ++ Program to implement the above approach ; Function to find the minimum of two numbers ; Function to find the maximum value possible of the given expression from all permutations of the array ; Stores the minimum value from the array ; Return the answer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int min ( int a , int b ) { return ( a > b ) ? b : a ; } int maximumModuloValue ( int A [ ] , int n ) { int mn = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { mn = min ( A [ i ] , mn ) ; } return mn ; } int main ( ) { int A [ ] = { 7 , 10 , 12 } ; int n = ( sizeof ( A ) / ( sizeof ( A [ 0 ] ) ) ) ; cout << maximumModuloValue ( A , n ) << endl ; return 0 ; }