text: Maximum difference between a pair of adjacent elements by excluding every element once | C # Program to implement the above approach ; Function to calculate maximum difference between adjacent elements excluding every array element once ; Compute maximum adjacent difference for whole array ; Store the maximum between arr_max and curr_max ; Append the result into a vector ; Print the result ; Driver Code
code: using System ; using System . Collections . Generic ; class GFG { static void maxAdjacent ( int [ ] arr , int N ) { List < int > res = new List < int > ( ) ; int arr_max = Int32 . MinValue ; for ( int i = 1 ; i < N ; i ++ ) { arr_max = Math . Max ( arr_max , Math . Abs ( arr [ i - 1 ] - arr [ i ] ) ) ; } for ( int i = 1 ; i < N - 1 ; i ++ ) { int curr_max = Math . Abs ( arr [ i - 1 ] - arr [ i + 1 ] ) ; int ans = Math . Max ( curr_max , arr_max ) ; res . Add ( ans ) ; } foreach ( int x in res ) Console . Write ( x + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 4 , 7 , 8 } ; int N = arr . Length ; maxAdjacent ( arr , N ) ; } }