Maximam circular sum

sir i wrote this code but it is not giving correct answer.
according to me my logic is correct. please tell me where i am doing wrong??

this is the code -

your approach is not correct
take this example
input
8
-1 40 -14 7 6 5 -4 -1
your output is 82 but correct output is 52

your output is wrong because of

  1. your are considering a element twice

  2. you are considering the only one possible combination of circular array
    -1 40 -14 7 6 5 -4 -1 -1 40 -14 7 6 5 -4
    this is not only one possible combination of circular array

what if i start my circular array from 7
then the array will be
7 6 5 -4 -1 -1 40 -14 7 6 5 -4 -1 -1 40 -14
which you are not considering

even if your try to do correct these things
then time complexity of your approach become very high and leads to TLE

so use kadan’s algorithm for circular subarray sum to solve this question

for kadane’s algorithm
see this post

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like :heart:: and don’t forgot to mark doubt as resolved :grinning:

1 Like

@asaurabh_26 thank u so much sir. i understood what i was doing wrong. this new code is running nd i also understood its working :grinning: :smiley: