Python prefix-sum solution | min_heap | Leetcode 2054
\ndef minSumOfLengths(self, arr: List[int], t: int) -> int:\n\tpsum = list(accumulate(arr))\n\tmp, cans = {0:-1}, []\n\tfor i in range(len(psum)):\n\t\tx = psum
```\ndef minSumOfLengths(self, arr: List[int], t: int) -> int:\n\tpsum = list(accumulate(arr))\n\tmp, cans = {0:-1}, []\n\tfor i in range(len(psum)):\n\t\tx = psum[i]-t\n\t\tif x in mp:\n\t\t\tcans.append([mp[x], i])\n\t\tmp[psum[i]] = i\n\n\tq, cur, ans = [], len(arr)+10, len(arr)+10\n\tfor s, e in cans:\n\t\twhile(q and q[0][0]<=s):\n\t\t\tcur = min(cur, heappop(q)[1])\n\t\tans = min(ans, cur+(e-s))\n\t\theappush(q, (e, e-s))\n\treturn ans if ans<=len(arr) else -1\n```\nSimilar problem:\n[2054. Two Best Non-Overlapping Events](https://leetcode.com/problems/two-best-non-overlapping-events/discuss/2693097/Python-solution-or-sort-%2B-minheap)
[]