[Python] One-pass, prefix-sum, O(n)
Keep track of the running prefix-sum and the length of the shortest sub-array that sums to the target up to that point (best_till in my solution).\nEach time we
Keep track of the running prefix-sum and the length of the shortest sub-array that sums to the target up to that point (`best_till` in my solution).\nEach time we find another such sub-array, look up that length value at the index right before it starts.\n```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        prefix = {0: -1}\n        best_till = [math.inf] * len(arr)\n        ans = best = math.inf\n        for i, curr in enumerate(itertools.accumulate(arr)):\n            if curr - target in prefix:\n                end = prefix[curr - target]\n                if end > -1:\n                    ans = min(ans, i - end + best_till[end])\n                best = min(best, i - end)\n            best_till[i] = best\n            prefix[curr] = i\n        return -1 if ans == math.inf else ans\n```\nIn the contest I misread sub-array as subsequence so ran out of time \uD83D\uDE22
['Prefix Sum', 'Python']