Find the largest contiguous pair sum in given Array | Python3 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
import sys NEW_LINE def largestSumpair ( arr , n ) : NEW_LINE INDENT pair = [ ] NEW_LINE max_sum = - sys . maxsize - 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if max_sum < ( arr [ i ] + arr [ i - 1 ] ) : NEW_LINE INDENT max_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 = [ 11 , - 5 , 9 , - 3 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE pair = largestSumpair ( arr , N ) NEW_LINE print ( pair [ 0 ] , end = " ▁ " ) NEW_LINE print ( pair [ 1 ] , end = " ▁ " ) NEW_LINE