Documented O(N) solution
```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        prefix = [float(\'inf\')]len(arr) # this array stores the mini
```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        prefix = [float(\'inf\')]*len(arr) # this array stores the minimum length of the subarray that ends at i or before that\n        suffix = [float(\'inf\')]*len(arr) # this array stores the minimum length of the subarray that starts at i or after that\n        \n        start = 0\n        currSum = 0\n        for index in range(len(arr)):\n            currSum += arr[index]\n            \n            while currSum > target:\n                currSum -= arr[start]\n                start += 1\n            \n            if currSum == target:\n                # populate prefix and suffix array.\n                # at this point we are simply storing the values for respective index not minimum\n                length = index-start+1\n                prefix[index] = length \n                suffix[start] = length\n        \n        # correcting prefix array\n        for index in range(1, len(arr)):\n            prefix[index] = min(prefix[index], prefix[index-1])\n        \n        # correcting suffix array\n        for index in range(len(arr)-2, -1, -1):\n            suffix[index] = min(suffix[index], suffix[index+1])\n        \n        \n\t\t# Working with the idea that a non overlapping subarray lies to right and left of an index, \n\t\t# so we select minimum subarray from the two halves of the array.  \n        minComb = float(\'inf\')\n        for index in range(1, len(arr)):\n            minComb = min(minComb, prefix[index-1]+suffix[index])\n        return minComb if minComb < float(\'inf\') else -1
[]