Python Prefix Sums, Heap (passes given test cases | feel free to modify to run all test cases)
```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        n = len(arr)\n        heap = []\n        prefix_sum = {}\n    
```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        n = len(arr)\n        heap = []\n        prefix_sum = {}\n        prefix_sum[0] = -1\n        curr_sum = 0\n        for i in range(n): \n            curr_sum += arr[i]\n            if prefix_sum.get(curr_sum - target):\n                heapq.heappush(heap,(i - prefix_sum.get(curr_sum - target), i))\n            prefix_sum[curr_sum] = i\n                \n        while len(heap) > 1:\n            len1, end1 = heapq.heappop(heap)\n            len2, end2 = heapq.heappop(heap)\n            if end1 <= end2 - len2 or end2 <= end1 - len1:    \n                return len1 + len2\n            else:    # overlap\n                heapq.heappush(heap, (len1, end1))\n                \n        return -1
['Heap (Priority Queue)', 'Prefix Sum', 'Python', 'Python3']