Maximize sum of second minimums of each K length partitions of the array | Function to find the maximum sum of second smallest of each partition of size K ; Sort the array A [ ] in ascending order ; Store the maximum sum of second smallest of each partition of size K ; Select every ( K - 1 ) th element as second smallest element ; Update sum ; Print the maximum sum ; Given size of partitions ; Given array A [ ] ; Size of the given array ; Function Call
function findSum ( A , N , K ) { A . sort ( ) ; let sum = 0 ; for ( let i = N / K ; i < N ; i += K - 1 ) { sum += A [ i ] ; } document . write ( sum ) ; } let K = 4 ; let A = [ 2 , 3 , 1 , 4 , 7 , 5 , 6 , 1 ] ; let N = A . length ; findSum ( A , N , K ) ;