Find the smallest contiguous sum pair in an Array | C # program to find the smallest sum contiguous pair ; Function to find the smallest sum contiguous pair ; Stores the contiguous pair ; Initialize minimum sum ; Checking for minimum value ; Add to pair ; Updating pair ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public static ArrayList smallestSumpair ( int [ ] arr , int n ) { ArrayList pair = new ArrayList ( ) ; int min_sum = int . MaxValue , i ; for ( i = 1 ; i < n ; i ++ ) { if ( min_sum > ( arr [ i ] + arr [ i - 1 ] ) ) { min_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 = { 4 , 9 , - 3 , 2 , 0 } ; int N = arr . Length ; ArrayList pair = new ArrayList ( ) ; pair = smallestSumpair ( arr , N ) ; Console . Write ( pair [ 0 ] + " ▁ " + pair [ 1 ] ) ; } }