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 ) possible for a pair in the array ; Stores the maximum value of ( arr [ i ] + i ) ; Stores the required result ; Traverse the array arr [ ] ; Calculate for current pair and update maximum value ; Update maxValue if ( arr [ i ] + I ) is greater than maxValue ; Print the result ; Driver code
def maximumValue ( arr , n ) : NEW_LINE INDENT maxvalue = arr [ 0 ] NEW_LINE result = 0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT result = max ( result , maxvalue + arr [ i ] - i ) NEW_LINE maxvalue = max ( maxvalue , arr [ i ] + i ) NEW_LINE DEDENT print ( result ) NEW_LINE DEDENT arr = [ 1 , 9 , 3 , 6 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE maximumValue ( arr , N ) NEW_LINE