Maximum circular subarray sum | C # program for maximum contiguous circular sum problem ; 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
using System ; class GFG { public static int maxCircularSum ( int [ ] a , int n ) { if ( n == 1 ) return a [ 0 ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } int curr_max = a [ 0 ] , max_so_far = a [ 0 ] , curr_min = a [ 0 ] , min_so_far = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { curr_max = Math . Max ( curr_max + a [ i ] , a [ i ] ) ; max_so_far = Math . Max ( max_so_far , curr_max ) ; curr_min = Math . Min ( curr_min + a [ i ] , a [ i ] ) ; min_so_far = Math . Min ( min_so_far , curr_min ) ; } if ( min_so_far == sum ) { return max_so_far ; } return Math . Max ( max_so_far , sum - min_so_far ) ; } public static void Main ( ) { int [ ] a = { 11 , 10 , - 20 , 5 , - 3 , - 5 , 8 , - 13 , 10 } ; int n = 9 ; Console . WriteLine ( " Maximum ▁ circular ▁ sum ▁ is ▁ " + maxCircularSum ( a , n ) ) ; } }