Simple python that apply prefix sum & heap
Intuition\n Describe your first thoughts on how to solve this problem. \nprefix sum + hash to find all qualified sub-array\nthen the problem is the same as 2054
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nprefix sum + hash to find all qualified sub-array\nthen the problem is the same as 2054. Two Best Non-Overlapping Events)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        \n        res = []\n        prefix = 0\n        dic = collections.defaultdict(int)\n        dic[0] = -1\n\n        for r in range(len(arr)):\n            prefix += arr[r]\n            if prefix - target in dic : \n                res.append([dic[prefix-target], r, r-dic[prefix-target]])\n            dic[prefix] = r\n        \n        if len(res) < 2 :\n            return -1 \n        res.sort()\n        pq = []\n        Min = inf\n        ans = inf \n        for i in range(len(res)):\n            while pq and pq[0][0] <= res[i][0]:\n                end, val = heapq.heappop(pq)\n                Min = min(Min, val)\n            \n            ans = min(ans, Min + res[i][2])\n            heapq.heappush(pq, (res[i][1],res[i][2]))\n\n        return ans if ans != inf else -1\n    \n```
['Heap (Priority Queue)', 'Prefix Sum', 'Python3']