[JAVA] Sliding window, beat 90% solutions, O(n)
\nclass Solution {\n    public int minSumOfLengths(int[] arr, int target) {\n        int[] min_len = new int[arr.length];\n        Arrays.fill(min_len, Integer.
```\nclass Solution {\n    public int minSumOfLengths(int[] arr, int target) {\n        int[] min_len = new int[arr.length];\n        Arrays.fill(min_len, Integer.MAX_VALUE);\n        \n        int sum = 0;\n        int start = 0;\n        int res = Integer.MAX_VALUE;\n        int min = Integer.MAX_VALUE;\n        \n        for(int end = 0; end < arr.length; end++){\n            sum += arr[end];\n            \n            while(sum > target){\n                sum -= arr[start++];\n            }\n            \n            if(sum == target){\n                int cur_len = end-start+1;\n                if(start > 0 && min_len[start-1] != Integer.MAX_VALUE){\n                    res = Math.min(res, cur_len + min_len[start-1]);\n                }\n                min = Math.min(min, cur_len);\n            }\n            min_len[end] = min;\n        }\n        \n        return res == Integer.MAX_VALUE ? -1 : res;\n    }\n}\n```
['Sliding Window', 'Java']