Minimize maximum difference between adjacent elements possible by removing a single array element | 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
function maxAdjacentDifference ( A ) { let diff = 0 ; for ( let i = 1 ; i < A . length ; i ++ ) { diff = Math . max ( diff , A [ i ] - A [ i - 1 ] ) ; } return diff ; } function MinimumValue ( arr , N ) { let MinValue = Number . MAX_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let new_arr = [ ] ; for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) continue ; new_arr . push ( arr [ j ] ) ; } MinValue = Math . min ( MinValue , maxAdjacentDifference ( new_arr ) ) ; } return MinValue ; } let arr = [ 1 , 3 , 7 , 8 ] ; let N = arr . length ; document . write ( MinimumValue ( arr , N ) ) ;