Coding Blocks not accepting my CODE

I have tried running my code on every test cases of this problem given in this problem by Coding Blocks, and it’s giving me the correct output.

But when I submit my code, it is showing that my code is not giving correct output for the first test case.

How come it’s possible?

Is it a technical glitch?

Please Help🙏

hello @Shivam01
pls share ur code using cb ide i will check.

My Code -> https://ide.codingblocks.com/s/367783

yeah there is one mistake in ur .

there are two cases.
a) prefix + suffix can make maximum ( u have included this )
b) contiguous subarray can make maximum (u missed this)

@Shivam01

check this.

The maximum subarray sum in circular array is maximum of following

  • Maximum subarray sum in non circular array
  • Maximum subarray sum in circular array.

Example - [1,2,5,-2,-3,5]
Steps -

  • Find the maximum subarray sum using Kadane Algorithm. This is maximum sum for non circular array.

  • 1+2+5 = 8
  • For non circular sum,
    Step 1) find the minimum subarray sum of array.

-2-3 = -5
Step 2) Now find the total sum of array = 1 + 2 + 5 -2 - 3 + 5 = 8
Step 3) The max subarray sum for circular array = Total Sum - Minimum subarray Sum
= 8 - (-5) = 8 + 5 = 13
As illustrated above, substracting minimum subarray sum from total sum gives maximum circular subarray sum.
Answer = Max ( Non circular max sum + circular max sum ) = max(8,13) = 13

Can you explain why max. of circular & non-circular sum is considered as the final answer?

we want max contigous sum . and we will pick that answer among the two case ,which will give maximum. that why max

Okky thank you very much Aman!!:blush: