Maximum sum of difference of adjacent elements | CPP program to find maximum sum of adjacent elements of permutation of n ; To find max sum of permutation ; Base case ; Otherwise max sum will be ( n * ( n - 1 ) / 2 ) - 1 + n / 2 ; Driver program to test maxSum ( )
#include <iostream> NEW_LINE using namespace std ; int maxSum ( int n ) { if ( n == 1 ) return 1 ; else return ( n * ( n - 1 ) / 2 ) - 1 + n / 2 ; } int main ( ) { int n = 3 ; cout << maxSum ( n ) ; return 0 ; }