Partition the array into two odd length groups with minimized absolute difference between their median | C ++ program to minimise the median between partition array ; Function to find minimise the median between partition array ; Sort the given array arr [ ] ; Return the difference of two middle element of the arr [ ] ; Driver Code ; Size of arr [ ] ; Function that returns the minimum the absolute difference between median of partition array
#include " bits / stdc + + . h " NEW_LINE using namespace std ; int minimiseMedian ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; return abs ( arr [ n / 2 ] - arr [ ( n / 2 ) - 1 ] ) ; } int main ( ) { int arr [ ] = { 15 , 25 , 35 , 50 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimiseMedian ( arr , n ) ; return 0 ; }