Split array into two subarrays such that difference of their maximum is minimum | javascript 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
function findMinDif ( arr , N ) { arr . sort ( ( a , b ) => a - b ) ; return ( arr [ N - 1 ] - arr [ N - 2 ] ) ; } var arr = [ 7 , 9 , 5 , 10 ] ; var N = arr . length ; document . write ( findMinDif ( arr , N ) ) ;