text: Maximize sum of absolute difference between adjacent elements in Array with sum K | Function for maximising 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: function maxAdjacentDifference ( N , K ) { if ( N == 1 ) { return 0 ; } if ( N == 2 ) { return K ; } return 2 * K ; } let N = 6 ; let K = 11 ; document . write ( maxAdjacentDifference ( N , K ) ) ;