💥💥 Beats 100% on runtime and memory [EXPLAINED]
IntuitionThe idea is to track the sum of elements as we go through the array and use a stack to keep track of previous sums and lengths. This helps to identify
# Intuition
The idea is to track the sum of elements as we go through the array and use a stack to keep track of previous sums and lengths. This helps to identify and store the longest sequence of subarrays that sum up in a way that allows us to create a non-decreasing subsequence.

# Approach
Iterate over the array, maintaining a running prefix sum and checking the stack for the best possible subarray to extend; for each element, we update the stack with the new sum and its corresponding subsequence length.

# Complexity
- Time complexity:
O(n) because we process each element of the array once, and each element is added and removed from the stack at most once.

- Space complexity:
O(n) due to the stack that stores intermediate results.

# Code
```typescript []
function findMaximumLength(nums: number[]): number {
    const n = nums.length;
    const stk: [number, number, number][] = [[0, 0, 0]]; // Stack to keep track of values
    let pre = 0;
    let res = 0;

    for (let i = 0, j = 0; i < n; i++) {
        pre += nums[i];
        j = Math.min(j, stk.length - 1);

        while (j + 1 < stk.length && pre >= stk[j + 1][0]) {
            j++;
        }

        const [val, prePre, preDp] = stk[j];
        const curDp = preDp + 1;
        res = curDp;

        const last = pre - prePre;
        while (stk.length > 0 && stk[stk.length - 1][0] >= last + pre) {
            stk.pop();
        }

        stk.push([last + pre, pre, curDp]);
    }

    return res;
}

```
['Dynamic Programming', 'Stack', 'Memoization', 'Queue', 'Heap (Priority Queue)', 'Monotonic Stack', 'TypeScript']