Maximum value of arr [ i ] + arr [ j ] + i â €“ j for any pair of an array | Function to find the maximum value of arr [ i ] + arr [ j ] + i - j over all pairs ; Stores the required result ; Traverse over all the pairs ( i , j ) ; Calculate the value of the expression and update the overall maximum value ; Print the result ; Driver Code
def maximumValue ( arr , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT ans = max ( ans , arr [ i ] + arr [ j ] + i - j ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT arr = [ 1 , 9 , 3 , 6 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE maximumValue ( arr , N ) NEW_LINE