Maximum value of | arr [ i ] | Return maximum | arr [ i ] - arr [ j ] | + | i - j | ; Calculating first_array and second_array ; Finding maximum and minimum value in first_array ; Storing the difference between maximum and minimum value in first_array ; Finding maximum and minimum value in second_array ; Storing the difference between maximum and minimum value in second_array ; Driver Code
def findValue ( arr , n ) : NEW_LINE INDENT a = [ ] NEW_LINE b = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT a . append ( arr [ i ] + i ) NEW_LINE b . append ( arr [ i ] - i ) NEW_LINE DEDENT x = a [ 0 ] NEW_LINE y = a [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] > x ) : NEW_LINE INDENT x = a [ i ] NEW_LINE DEDENT if ( a [ i ] < y ) : NEW_LINE INDENT y = a [ i ] NEW_LINE DEDENT DEDENT ans1 = ( x - y ) NEW_LINE x = b [ 0 ] NEW_LINE y = b [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( b [ i ] > x ) : NEW_LINE INDENT x = b [ i ] NEW_LINE DEDENT if ( b [ i ] < y ) : NEW_LINE INDENT y = b [ i ] NEW_LINE DEDENT DEDENT ans2 = ( x - y ) NEW_LINE return max ( ans1 , ans2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findValue ( arr , n ) ) NEW_LINE DEDENT