Meaning of circular subaaray

circular subarray???

Hello @Bhavit_Singla,

You have to consider the array as circular though it is linear.
This means that you should not consider 12 as the last element.

You are supposed to check for the sum of the element in a circular fashion like:
12,8 =20
-11,12,8 =9
12,8,-8 =12
And so on…

In your case the maximum sum appears with the elements in a circular fashion:
12,8,-8,9,-9,10 = 22

It’s the same as maximum subarray sum.

You have to solve this question for in two parts:
Algorithm:

  1. maximum sum possible in linear manner , use kadane’s algorithm to compute this (say max_linear)

  2. Find the maximum sum possible in circular manner:
    …First negate all the elements of the array. i.e. covert negative nos. to positive and vice-a-versa example: 1- to 1 and 5 to -5.
    …Now, apply kadane’s algorithm on this modified array and find maximum value which the minimum value for actual array(say min2).
    …At last, add this min2 to the sum of all the elements of the actual array (say max2).

  3. Compare max1 and max2.

  4. Print the maximum of both.

Hope, this would help.
Give a like, if you are satisfied.