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, then abs(x) = -x.
	If x is a non-negative integer, then abs(x) = x.


&nbsp;
Example 1:

Input: nums = [1,-3,2,3,-4]
Output: 5
Explanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.


Example 2:

Input: nums = [2,-5,1,-4,3,-2]
Output: 8
Explanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	-104 &lt;= nums[i] &lt;= 104


class Solution:
	def maxAbsoluteSum(self, A):

		ma,mi,res = 0,0,0
		for a in A:
			ma = max(0,ma+a)
			mi = min(0,mi+a)
			res = max(res,ma,-mi)
		return res
class Solution {
    public int maxAbsoluteSum(int[] nums) {
        int minSum = Integer.MAX_VALUE, maxSum = Integer.MIN_VALUE, currentMinSum = 0, currentMaxSum = 0;
        for(int num: nums) {
            currentMaxSum += num;
            maxSum = Math.max(maxSum, currentMaxSum);
            if (currentMaxSum < 0)
                currentMaxSum = 0;

            currentMinSum += num;
            minSum = Math.min(minSum, currentMinSum);
            if (currentMinSum > 0)
                currentMinSum = 0;
        }
        return Math.max(maxSum, -minSum);
    }
}
class Solution {
public:
    int maxAbsoluteSum(vector<int>& nums) {
        int mx1=0;
        int sum=0;
        for(int i=0;i<nums.size();i++){
            sum+=nums[i];
            if(sum<0)sum=0;
            mx1=max(sum,mx1);
        }
        sum=0;
        int mx2=0;
        for(int i=0;i<nums.size();i++){
            sum+=nums[i];
            if(sum>=0)sum=0;
            mx2=min(sum,mx2);
        }
        
        return max(mx1,abs(mx2));
    }
};
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxAbsoluteSum = function(nums) {
    maxi = Number.MIN_VALUE , mini = Number.MAX_VALUE
    cur_max = 0, cur_min = 0
    for(let i=0; i<nums.length; i++){
        cur_max = Math.max(cur_max+nums[i],nums[i])
        cur_min = Math.min(cur_min+nums[i], nums[i])
        maxi = Math.max(maxi,cur_max)
        mini = Math.min(mini,cur_min)
    }
    return Math.max(maxi,-mini)
};
Maximum Absolute Sum of Any Subarray