text: Maximum difference between a pair of adjacent elements by excluding every element once | C # program for the above approach ; Function to calculate maximum difference between adjacent elements excluding every array element once ; Traverse the array ; Stores the maximum diff ; Check for maximum adjacent element ; Exclude current element ; Update maximum difference ; Update previous value ; Append the result into a vector ; Print the result ; Driver Code
code: using System ; using System . Collections . Generic ; public class GFG { static void maxAdjacent ( int [ ] arr , int N ) { List < int > res = new List < int > ( ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { int prev = arr [ 0 ] ; int maxi = Int32 . MinValue ; for ( int j = 1 ; j < N ; j ++ ) { if ( i == j ) continue ; maxi = Math . Max ( maxi , Math . Abs ( arr [ j ] - prev ) ) ; prev = arr [ j ] ; } res . Add ( maxi ) ; } foreach ( int x in res ) { Console . Write ( x + " ▁ " ) ; } Console . WriteLine ( ) ; } static public void Main ( ) { int [ ] arr = { 1 , 3 , 4 , 7 , 8 } ; int N = arr . Length ; maxAdjacent ( arr , N ) ; } }