Minimize maximum difference between adjacent elements possible by removing a single array element | Python3 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
import sys NEW_LINE def maxAdjacentDifference ( A ) : NEW_LINE INDENT diff = 0 NEW_LINE for i in range ( 1 , len ( A ) , 1 ) : NEW_LINE INDENT diff = max ( diff , A [ i ] - A [ i - 1 ] ) NEW_LINE DEDENT return diff NEW_LINE DEDENT def MinimumValue ( arr , N ) : NEW_LINE INDENT MinValue = sys . maxsize NEW_LINE for i in range ( N ) : NEW_LINE INDENT new_arr = [ ] NEW_LINE for j in range ( N ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT continue NEW_LINE DEDENT new_arr . append ( arr [ j ] ) NEW_LINE DEDENT MinValue = min ( MinValue , maxAdjacentDifference ( new_arr ) ) NEW_LINE DEDENT return MinValue NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 3 , 7 , 8 ] NEW_LINE N = len ( arr ) NEW_LINE print ( MinimumValue ( arr , N ) ) NEW_LINE DEDENT