I have an array A
containing integers (positive, negative or zero). So, I want to get the maximum absolute range sum (something like Kadane's algorithm
, but with absolute value).
For example, let A be:
A = [-3, 2 ,-3, 1]
so the answer there is 4 as abs(A[0] + A[1] + A[2]) = 4.
I tried to find the solution using Kadane's algorithm maintaining a current maximum sum, but it seems not to work in some cases. Is there a way to get the answer?
Expected time complexity: O(n*log(n))