Sort the array
arr . sort ( function ( a , b ) { return a - b ; } ) ; let b = Math . floor ( Math . ceil ( n / k ) ) ; let min_sum = 0 , max_sum = 0 ; for ( let i = 0 ; i < b ; i ++ ) min_sum += arr [ i ] ; for ( let i = 2 ; i < arr . length ; i ++ ) max_sum += arr [ i ] ;