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 ; Prvar the result ; Driver Code
function maximumValue ( arr , n ) { var maxvalue = arr [ 0 ] ; var result = 0 ; for ( i = 1 ; i < n ; i ++ ) { result = Math . max ( result , maxvalue + arr [ i ] - i ) ; maxvalue = Math . max ( maxvalue , arr [ i ] + i ) ; } document . write ( result ) ; } var arr = [ 1 , 9 , 3 , 6 , 5 ] ; var N = arr . length ; maximumValue ( arr , N ) ;