Find the smallest contiguous sum pair in an Array | 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
function smallestSumpair ( arr , n ) { let pair = [ ] ; let min_sum = Number . MAX_VALUE , i ; for ( i = 1 ; i < n ; i ++ ) { if ( min_sum > ( arr [ i ] + arr [ i - 1 ] ) ) { min_sum = arr [ i ] + arr [ i - 1 ] ; if ( pair . length == 0 ) { pair . push ( arr [ i - 1 ] ) ; pair . push ( arr [ i ] ) ; } else { pair [ 0 ] = arr [ i - 1 ] ; pair [ 1 ] = arr [ i ] ; } } } return pair ; } let arr = [ 4 , 9 , - 3 , 2 , 0 ] ; let N = arr . length ; let pair = smallestSumpair ( arr , N ) ; document . write ( pair [ 0 ] + " " + pair [ 1 ] ) ;