hello sir/ma’am, How to handle the case if all negative numbers are there in the given array??
eg: [-2,-3,-1] is the given array. then max possible sum is -1. Here, kadane’s algo fails…
Max Subarray Sum
@priyanshi.agarwal3405 Hi, the kadane’s algorithm requires at least one positive input to work, so this is not a valid input. It is a shortcoming of this algorithm. To make the code suitable for all inputs, you can check if the maximum sum is coming out to be 0, and in that case return the least negative number.
Okay Ma’am , got it. Thank you