4. Maximum Absolute Sum of Any Subarray
You are given an integer array nums
. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr]
is abs(numsl + numsl+1 + ... + numsr-1 + numsr)
.
Return the maximum absolute sum of any (possibly empty) subarray of nums
.
Note that abs(x)
is defined as follows:
If
x
is a negative integer, thenabs(x) = -x
.If
x
is a non-negative integer, thenabs(x) = x
.
Example 1:
Example 2:
Solution: (Using Kadane's Algorithm)
Approach: Finding the max Sum possible Finding the min sum possible Checking the max.
Time Complexity: O(n)
Last updated