Java O(n) time, O(n) space using two pointers
```class Solution {\n    public int minSumOfLengths(int[] arr, int target) {\n        int[] minsFound = new int[arr.length + 1];\n        minsFound[0] = 2 * arr
```class Solution {\n    public int minSumOfLengths(int[] arr, int target) {\n        int[] minsFound = new int[arr.length + 1];\n        minsFound[0] = 2 * arr.length;\n        int minLen = 2 * arr.length;\n        int twoMinLens = 2 * arr.length;\n        int sum = 0;\n        int b = 0;\n        int e = 0;\n        while (b < arr.length) {\n            if (sum == target) {\n                minLen = Math.min(e - b, minLen);\n                twoMinLens = Math.min(twoMinLens, e - b + minsFound[b]);\n            }\n            if (sum >= target || e == arr.length) {\n                sum -= arr[b];\n                b++;\n            } else {\n                minsFound[e] = minLen;\n                sum += arr[e];\n                e++;\n            }\n        }\n        return twoMinLens < 2 * arr.length ? twoMinLens : -1;\n    }\n}
['Java']