Finding minimal absolute sum of a subarray
问题 There's an array A containing (positive and negative) integers. Find a (contiguous) subarray whose elements' absolute sum is minimal, e.g.: A = [2, -4, 6, -3, 9] |(−4) + 6 + (−3)| = 1 <- minimal absolute sum I've started by implementing a brute-force algorithm which was O(N^2) or O(N^3) , though it produced correct results. But the task specifies: complexity: - expected worst-case time complexity is O(N*log(N)) - expected worst-case space complexity is O(N) After some searching I thought that