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 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
using System ; class GFG { static void maximumValue ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { ans = Math . Max ( ans , arr [ i ] + arr [ j ] + i - j ) ; } } Console . Write ( ans ) ; } static void Main ( ) { int [ ] arr = { 1 , 9 , 3 , 6 , 5 } ; int N = arr . Length ; maximumValue ( arr , N ) ; } }