Combination of sliding window, suffix sum and binary search.
\nint minSumOfLengths(vector<int>& arr, int target) {\n        vector<vector<int>> indices;\n        int si=0,ei=0,count=0;\n\t\t//using count to store the curr
```\nint minSumOfLengths(vector<int>& arr, int target) {\n        vector<vector<int>> indices;\n        int si=0,ei=0,count=0;\n\t\t//using count to store the current sum of values b/w si and ei (both inclusive)\n        for(;ei < arr.size();ei++){\n            count+=arr[ei];\n            while(si <= ei && count > target){\n                count-=arr[si++];\n            }\n            if(count == target){\n\t\t\t//found a match, so save the indices\n                indices.push_back({si,ei});\n                count-=arr[si++];\n            }\n        }\n\t\t//storing the length of the minimum subarray so far from the right side in the suffix array\n        vector<int> suffix(indices.size(),1e9);\n        int mins=1e9;\n        for(int i=indices.size()-1;i>-1;i--){\n            suffix[i] = min(mins,indices[i][1]-indices[i][0]+1);\n            mins = suffix[i];\n        }\n        int ans=1e9;\n        if(indices.size() == 0)return -1;\n        for(int i=0;i<indices.size()-1;i++){\n\t\t//for every subarray look for the minimum length subarray towards its right side. \n\t\t//Binary search the subarray with the minimum starting index but not overlapping with the current subarray. \n\t\t//Use the value corresponding to that subarray in the suffix sum as it will be the minimum value.\n\t\t//Keep updating the answer.\n            int a = binary(indices, i+1,indices.size()-1,indices[i][1],suffix);\n            if(a!=-1){\n                ans = min(ans, a + indices[i][1]-indices[i][0]+1 );\n            }\n        }\n        if(ans!=1e9)return ans;\n        return -1;\n    }\n    \n    int binary(vector<vector<int>>& indices, int si,int ei,int target,vector<int>& suffix){\n        int ans=-1;\n        while(si <= ei){\n            int mid = si + (ei - si)/2;\n            if(indices[mid][0] > target){\n                ans = suffix[mid];\n                ei = mid-1;\n            }else{\n                si = mid+1;\n            }\n        }\n        return ans;\n    }\n```
['Binary Search', 'Sliding Window']