Maximum value of arr [ i ] + arr [ j ] + i â €“ j for any pair of an array | C # program for the above approach ; Function to find the maximum value of arr [ i ] + arr [ j ] + i - j over all pairs ; 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
using System ; class GFG { static void maximumValue ( int [ ] arr , int n ) { int maxvalue = arr [ 0 ] ; int result = 0 ; for ( int i = 1 ; i < n ; i ++ ) { result = Math . Max ( result , maxvalue + arr [ i ] - i ) ; maxvalue = Math . Max ( maxvalue , arr [ i ] + i ) ; } Console . Write ( result ) ; } static void Main ( ) { int [ ] arr = { 1 , 9 , 3 , 6 , 5 } ; int N = arr . Length ; maximumValue ( arr , N ) ; } }