[Java] Two Pointer, One Iteration, One temporary Array
\nclass Solution {\n    public int minSumOfLengths(int[] arr, int target) {       \n        int[] left = new int[arr.length+2];\n        Arrays.fill(left, Integ
```\nclass Solution {\n    public int minSumOfLengths(int[] arr, int target) {       \n        int[] left = new int[arr.length+2];\n        Arrays.fill(left, Integer.MAX_VALUE/2);\n        \n        int start = 0;\n        int end = 0;\n        int sum = 0;\n        int result = Integer.MAX_VALUE/2;\n        while(end < arr.length || sum > target){\n            if(sum < target){\n                sum+=arr[end++];\n            } else {\n                sum-=arr[start++];\n            }\n            if(sum == target){\n                int len = end - start;\n                left[end+1] = len;\n                result = Math.min(result, len + left[start+1]);\n            }\n            left[end+1] = Math.min(left[end],left[end+1]);\n        }\n        return result == Integer.MAX_VALUE/2 ? -1 : result;\n    }\n}\n```
[]