Solution in Javascript
Code\n\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaximumLength = function(nums) {\n  const n = nums.length\n  //last + pre, pre, dp\n  
# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaximumLength = function(nums) {\n  const n = nums.length\n  //last + pre, pre, dp\n  const stk = [[0,0,0]]\n\n  let pre = 0, res = 0\n  let i = 0, j = 0\n\n  while (i < n) {\n      pre += nums[i]\n      j = Math.min(j, stk.length-1)\n\n      while ((j+1) < stk.length && pre >= stk[j+1][0]) {\n          j += 1\n      }\n\n      const [_, pre_pre, pre_dp] = stk[j]\n      let curr_dp = pre_dp + 1\n      res = curr_dp\n\n      const last = pre - pre_pre\n      while (stk.length>0 && stk[stk.length-1][0] >= last+pre){\n          stk.pop()\n      }\n\n      stk.push([last+pre, pre, curr_dp])\n      i+=1\n  }\n\n  return res\n}\n```
['JavaScript']