Maximum circular subarray sum | The function returns maximum circular contiguous sum in a [ ] ; Corner Case ; Initialize sum variable which store total sum of the array . ; Initialize every variable with first value of array . ; Concept of Kadane 's Algorithm ; Kadane 's Algorithm to find Maximum subarray sum. ; Kadane 's Algorithm to find Minimum subarray sum. ; returning the maximum value ; Driver code
def maxCircularSum ( a , n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return a [ 0 ] NEW_LINE DEDENT sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += a [ i ] NEW_LINE DEDENT curr_max = a [ 0 ] NEW_LINE max_so_far = a [ 0 ] NEW_LINE curr_min = a [ 0 ] NEW_LINE min_so_far = a [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT curr_max = max ( curr_max + a [ i ] , a [ i ] ) NEW_LINE max_so_far = max ( max_so_far , curr_max ) NEW_LINE curr_min = min ( curr_min + a [ i ] , a [ i ] ) NEW_LINE min_so_far = min ( min_so_far , curr_min ) NEW_LINE DEDENT if ( min_so_far == sum ) : NEW_LINE INDENT return max_so_far NEW_LINE DEDENT return max ( max_so_far , sum - min_so_far ) NEW_LINE DEDENT a = [ 11 , 10 , - 20 , 5 , - 3 , - 5 , 8 , - 13 , 10 ] NEW_LINE n = len ( a ) NEW_LINE print ( " Maximum ▁ circular ▁ sum ▁ is " , maxCircularSum ( a , n ) ) NEW_LINE