Minimize maximum difference between adjacent elements possible by removing a single array element | C # program to implement the above approach ; Function to find maximum difference between adjacent array elements ; Store the maximum difference ; Traverse the array ; Update maximum difference ; Function to calculate the minimum of maximum difference between adjacent array elements possible by removing a single array element ; Stores the required minimum ; Stores the updated array ; Skip the i - th element ; Update MinValue ; Return MinValue ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int maxAdjacentDifference ( List < int > A ) { int diff = 0 ; for ( int i = 1 ; i < A . Count ; i ++ ) { diff = Math . Max ( diff , A [ i ] - A [ i - 1 ] ) ; } return diff ; } static int MinimumValue ( int [ ] arr , int N ) { int MinValue = Int32 . MaxValue ; for ( int i = 0 ; i < N ; i ++ ) { List < int > new_arr = new List < int > ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( i == j ) continue ; new_arr . Add ( arr [ j ] ) ; } MinValue = Math . Min ( MinValue , maxAdjacentDifference ( new_arr ) ) ; } return MinValue ; } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 3 , 7 , 8 } ; int N = arr . Length ; Console . WriteLine ( MinimumValue ( arr , N ) ) ; } }