diff --git a/Arrays/MaximumCircularSum.md b/Arrays/MaximumCircularSum.md new file mode 100644 index 0000000..a822ac8 --- /dev/null +++ b/Arrays/MaximumCircularSum.md @@ -0,0 +1,59 @@ +# Maximum Circular Sum +This question involves the usage of an algorithm known as Kadane's Algorithm +## Question +You are provided n numbers (both +ve and -ve). Numbers are arranged in a circular form. You need to find the maximum sum of consecutive numbers. +``` +Input Format +First line contains integer t which is number of test case. +For each test case, it contains an integer n which is the size of array and next line contains n space separated integers denoting the elements of the array. + +Constraints +1<=t<=100 +1<=n<=1000 +|Ai| <= 10000 + +Output Format +Print the maximum circular sum for each testcase in a new line. +``` + +## Code +``` +#include +#include +using namespace std; + +int main() +{ + int n; cin>>n; + int i,arr[n]; + for(i=0; i>arr[i]; + int maxSum=INT_MIN, minSum=INT_MAX, currsum1=0, currsum2=0; + int TotalSum=0; + for (i=0; imaxSum) maxSum=currsum1; + if (currsum20) currsum2=0; + } + if (minSum==TotalSum) cout< TotalSum-minSum) cout<