Find the smallest contiguous sum pair in an Array | Python3 program to find the smallest sum contiguous pair ; Function to find the smallest sum contiguous pair ; Contiguous pair ; isntialize minimum sum with maximum value ; checking for minimum value ; Add to pair ; Updating pair ; Driver code
import sys NEW_LINE def smallestSumpair ( arr , n ) : NEW_LINE INDENT pair = [ ] NEW_LINE min_sum = sys . maxsize NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if min_sum > ( arr [ i ] + arr [ i - 1 ] ) : NEW_LINE INDENT min_sum = arr [ i ] + arr [ i - 1 ] NEW_LINE if pair == [ ] : NEW_LINE INDENT pair . append ( arr [ i - 1 ] ) NEW_LINE pair . append ( arr [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT pair [ 0 ] = arr [ i - 1 ] NEW_LINE pair [ 1 ] = arr [ i ] NEW_LINE DEDENT DEDENT DEDENT return pair NEW_LINE DEDENT arr = [ 4 , 9 , - 3 , 2 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE pair = smallestSumpair ( arr , n ) NEW_LINE print ( pair [ 0 ] , pair [ 1 ] ) NEW_LINE