text: Maximize sum of absolute difference between adjacent elements in Array with sum K | C ++ program to maximize the sum of absolute differences between adjacent elements ; Function for maximizing the sum ; Difference is 0 when only one element is present in array ; Difference is K when two elements are present in array ; Otherwise ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int maxAdjacentDifference ( int N , int K ) { if ( N == 1 ) { return 0 ; } if ( N == 2 ) { return K ; } return 2 * K ; } int main ( ) { int N = 6 ; int K = 11 ; cout << maxAdjacentDifference ( N , K ) ; return 0 ; }