Maximize the sum of differences of consecutive elements after removing exactly K elements | Function to return the maximized sum ; Remove any k internal elements ; Driver code
function findSum ( arr , n , k ) { if ( k <= n - 2 ) return ( arr [ n - 1 ] - arr [ 0 ] ) ; return 0 ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; var k = 1 ; document . write ( findSum ( arr , n , k ) ) ;