[c++] easy  2-pointer O(N) constant space solution explained
m1 = length of smallest subarray\nm2= length of 2nd smallest\nl= length of subarray\nstart=starting index of current subarray\nend = ending index of prev subarr
m1 = length of smallest subarray\nm2= length of 2nd smallest\nl= length of subarray\nstart=starting index of current subarray\nend = ending index of prev subarray +1\nI am subtracting the current index value from sum which was equal to target. As soon as sum becomes negative I add the initial value of the subarray and decrease the counter l till sum is negative. When sum = 0 if the length of the new subarray is less than m1, I update m1 with l, m2 with m1 and ending of this new subarray with current index i, but if the length of current subarray is greater than m1 but less than m2 I check if the subarrays are overlapping, if not then I update m2.\nI check for sum =0 condition again outside the loop in case if the last index of array makes the sum =0.\n```\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& a, int target) {\n        if(a.size()<=1)return -1;\n        int m1=INT_MAX,m2=INT_MAX,l=0,sum=target,start=0,end=-1;\n        for(int i=0;i<a.size();i++){\n            if(sum==0){\n                if(l<m1){if(start>=end)m2=m1;m1=l;end=i;}\n                else if(l<m2 && start>=end){m2=l;end=i;}\n                l--;\n                sum+=a[start++];\n            }\n           sum-=a[i];\n            l++;\n            if(sum<0){\n                while(sum<0){sum+=a[start++];l--;}\n            }\n\n        }\n         \n        if(sum==0){\n                if(l<m1 ){if(start>=end)m2=m1;m1=l;}\n                else if(l<m2 && start>=end){m2=l;}\n        }\n        if(m1==INT_MAX || m2==INT_MAX )return -1;\n        else return m1+m2;\n    }\n};\n```
['Two Pointers', 'C', 'Sliding Window', 'C++']