Partition the array into two odd length groups with minimized absolute difference between their median | Java 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
import java . util . * ; class GFG { static int minimiseMedian ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; return Math . abs ( arr [ n / 2 ] - arr [ ( n / 2 ) - 1 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 15 , 25 , 35 , 50 } ; int n = arr . length ; System . out . println ( minimiseMedian ( arr , n ) ) ; } }