Maximize the sum of differences of consecutive elements after removing exactly K elements | Java implementation of the approach ; Function to return the maximized sum ; Remove any k internal elements ; Driver code
class GFG { static int findSum ( int [ ] arr , int n , int k ) { if ( k <= n - 2 ) return ( arr [ n - 1 ] - arr [ 0 ] ) ; return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; int k = 1 ; System . out . println ( findSum ( arr , n , k ) ) ; } }