Split array into K | Function to find the minimum sum of 2 nd smallest elements of each subset ; Sort the array ; Stores minimum sum of second elements of each subset ; Traverse first K 2 nd smallest elements ; Update their sum ; Prvar the sum ; Given Array ; Given length of array ; Given subset lengths
function findMinimum ( arr , N , K ) { arr . sort ( ( a , b ) => a - b ) ; var ans = 0 ; for ( i = 1 ; i < 2 * ( parseInt ( N / K ) ) ; i += 2 ) { ans += arr [ i ] ; } document . write ( ans ) ; } var arr = [ 11 , 20 , 5 , 7 , 8 , 14 , 2 , 17 , 16 , 10 ] ; var N = arr . length ; var K = 5 ; findMinimum ( arr , N , K ) ;