Split array into two subarrays such that difference of their maximum is minimum | Java Program to split a given array such that the difference between their maximums is minimized . ; Sort the array ; Return the difference between two highest elements ; Driver code
import java . util . * ; class GFG { static int findMinDif ( int arr [ ] , int N ) { Arrays . sort ( arr ) ; return ( arr [ N - 1 ] - arr [ N - 2 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 9 , 5 , 10 } ; int N = arr . length ; System . out . println ( findMinDif ( arr , N ) ) ; } }