APPROACH OF THE QUESTION

APPROACH OF THE QUESTION

Hello @anmolaggarwal.432 the approach for the question is very simple:
have you solved normal maximum subarray sum using kadanes?

First you need to solve using normal Kadane’s algorithm. Call it as S1.

After that make all elements negative, and then find maximal possible sum using kadane. Add this to total sum of the array. Call this S2.
Now your answer is the maximum of S1 and S2.

Make all the elements of the array negative??Please explain this I havent understood

@anmolaggarwal.432 to find out the effect of the non contributing elements as well we have to do this:
like take this example:

For an array, say 10, -3, -4, 7, 6, 5, -4, -1
Cumulative Sum of the original array is 16
Now inverting this array it becomes -10, 3, 4, -7, -6, -5, 4, 1
Now applying Kadane’s algorithm on this new array we get the sum as 7 i.e from index 1 to 2.
cumulative_sum - (-7) i.e 16+7 which is 23
so our answer is 23

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.