C++ sliding window
\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& arr, int target) {\n        int sum = 0, n = arr.size(), ans = INT_MAX, len = INT_MAX;\n      
```\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& arr, int target) {\n        int sum = 0, n = arr.size(), ans = INT_MAX, len = INT_MAX;\n        vector<int> min_len(n, INT_MAX);\n        int start = 0;\n        for (int end = 0; end < n; end++) {\n            sum += arr[end];\n            //shrink the window\n            while (sum > target) {\n                sum -= arr[start];\n                start++;\n            }\n            if (sum == target) {\n                //update the min_len\n                int curLen = end - start + 1;\n                if (start > 0 && min_len[start-1] != INT_MAX) {\n                    ans = min(ans, curLen + min_len[start-1]);\n                }\n                len = min(curLen, len); \n            }\n            min_len[end] = len;\n        }\n        return ans == INT_MAX ? -1 : ans;\n    }\n};\n```
['C']