Subarray sum for all negative array

is all negative array is valid input for maximum subarray sum?

No, there must be atleast one positive no, otherwise as per Kadane algo, the sum will 0 always, since cumulative sum will be negative at every stage

what if we use other methods like three nested loop?

It will increase the time complexity, and generally in the sample input, you will never find all inputs to be negative. There will be atleast one positive no

@abhishekm Hey abhishek you can calculate the maximum SubArray Sum of negative elements of array by kadane’s algorithm. Refer above code. In my code i only interchange the position of if block of code which shown in the video and also initialized the maximumSum=INT_MIN.

If you not getting this code than surely i will help.

code Link : https://ide.codingblocks.com/s/78212

@abhishekm I hope I’ve cleared your doubt. Please mark this doubt as resolved and rate me on the basis of your experience. Rating option is just below where you mark this doubt as resolve. Your feedback is very important. It helps us to 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.