To store first and second maximums
f_max = a [ 0 ] NEW_LINE s_max = - ( sys . maxsize - 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] <= f_min ) : NEW_LINE INDENT s_min = f_min NEW_LINE f_min = a [ i ] NEW_LINE DEDENT elif ( a [ i ] < s_min ) : NEW_LINE INDENT s_min = a [ i ] NEW_LINE DEDENT if ( a [ i ] >= f_max ) : NEW_LINE INDENT s_max = f_max NEW_LINE f_max = a [ i ] NEW_LINE DEDENT elif ( a [ i ] > s_max ) : NEW_LINE INDENT s_max = a [ i ] NEW_LINE DEDENT DEDENT return min ( ( f_max - s_min ) , ( s_max - f_min ) ) NEW_LINE