[Python] One pass
It\'s standard to find valid intervals with sum equal to target. To find the min sum of lengths, we maintain the minimal length of such intervals that don\'t ov
It\'s standard to find valid intervals with sum equal to `target`. To find the min sum of lengths, we maintain the minimal length of such intervals that don\'t overlap with current interval, and keep the min of sum when we traverse all possible intervals.\n```\n   def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        min_l = math.inf\n        d = {0: -1}\n        q = deque()\n        s = 0\n        res = math.inf\n        for right_end, a in enumerate(arr):\n            s += a\n            if (s - target) in d:\n                left_end = d[s - target]\n\t\t        # The current interval is (left_end, right_end], left_end excluded. \n                cur_l = right_end - left_end\n\t\t\t\t# q maintain all previous valid intervals with [right_end, interval_length].\n                while q and q[0][0] <= left_end:\n                    min_l = min(min_l, q.popleft()[1])\n\t\t\t\t# We can take any interval whose right_end <= current left end, we might as well take the shortest one.\n                res = min(res, min_l + cur_l)\n                q.append([i, cur_l])\n            d[s] = right_end\n        if res < math.inf:\n            return res\n        return -1\n```
['Queue', 'Python']