Find the largest contiguous pair sum in given Array | C # program to find the a contiguous pair from the which has the largest sum ; Function to find and return the largest sum contiguous pair ; Stores the contiguous pair ; Initialize maximum sum ; Compare sum of pair with max_sum ; Insert the pair ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public static ArrayList largestSumpair ( int [ ] arr , int n ) { ArrayList pair = new ArrayList ( ) ; int max_sum = int . MinValue , i ; for ( i = 1 ; i < n ; i ++ ) { if ( max_sum < ( arr [ i ] + arr [ i - 1 ] ) ) { max_sum = arr [ i ] + arr [ i - 1 ] ; if ( pair . Count == 0 ) { pair . Add ( arr [ i - 1 ] ) ; pair . Add ( arr [ i ] ) ; } else { pair [ 0 ] = arr [ i - 1 ] ; pair [ 1 ] = arr [ i ] ; } } } return pair ; } public static void Main ( string [ ] args ) { int [ ] arr = { 11 , - 5 , 9 , - 3 , 2 } ; int N = arr . Length ; ArrayList pair = new ArrayList ( ) ; pair = largestSumpair ( arr , N ) ; foreach ( int it in pair ) { Console . Write ( it + " ▁ " ) ; } } }