[Python3] prefix sum
\n\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        ans = inf \n        best = [inf]*len(arr) # shortest subarray e
\n```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        ans = inf \n        best = [inf]*len(arr) # shortest subarray ending at i\n        prefix = 0\n        latest = {0: -1}\n        for i, x in enumerate(arr): \n            prefix += x\n            if prefix - target in latest: \n                ii = latest[prefix - target]\n                if ii >= 0: \n                    ans = min(ans, i - ii + best[ii])\n                best[i] = i - ii\n            if i: best[i] = min(best[i-1], best[i])\n            latest[prefix] = i \n        return ans if ans < inf else -1\n```
['Python3']