Python3 O(n)  using prefix sum strategy
\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        \n        hashTable = defaultdict(int)\n        hashTable[0] = -1
```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        \n        hashTable = defaultdict(int)\n        hashTable[0] = -1\n        summation = 0\n        for i in range(len(arr)):\n            summation = summation + arr[i]\n            hashTable[summation] = i\n        \n        summation = 0\n        minimumLeft = float(\'inf\')\n        result = float(\'inf\')\n        for i in range(len(arr)):\n            summation = summation + arr[i]\n            if summation - target in hashTable:\n                leftLength = i-hashTable[summation-target]\n                minimumLeft = min(minimumLeft,leftLength)\n            if summation + target in hashTable and minimumLeft < float(\'inf\'):\n                rightLength = hashTable[summation+target]-i\n                result = min(result,hashTable[summation+target]-i+minimumLeft)\n        \n        if result == float(\'inf\'):\n            return -1\n        return result\n\t```\n\t\n\t\n\tInspired from @pramitb Java Solution
[]