You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// First Approach - One pass dynamic programming approach counting positive and negative sums (nice trick "zeroing" positive and
// negative sum whenever it becomes negative or positive, respectively). (https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/solutions/6470626/0-ms-positive-and-negative-sum-o-n-o-1-beats-100-00/?envType=daily-question&envId=2025-02-26)
function maxAbsoluteSum(a: number[]) {
let psm = 0; // positive sum max
let nsm = 0; // negative sum max
for(let i = 0, ps = 0, ns = 0; i < a.length; ++i) {