[C++] || Sliding Window + Binary Search + Preprocessing
Solution consists mainly of 3 parts.\n\n Part-1 Using sliding window, get all intervals where sum == tagret . iv stores [s,e] , where interval summation [s,e] =
* Solution consists mainly of 3 parts.\n\n* **Part-1** Using sliding window, get all intervals where `sum == tagret` . `iv` stores `[s,e]` , where interval `summation [s,e]` `== target`.\n\n* **Part-2** Get Minimum length of each interval starting from right hand side and store the current minimum length at each index. This vector helps in choosing the optimal second subarray in **part 3**\n\n* **Part-3** Pick index `i` as first subarray. To find other subarray length, Find upper bound of ending point of first interval, which is done by `upper_bound` function. At that index `idx`, every subarray after `idx` is good to pick for second subarry. But we want the one with min length. **minLen is pre calculated** which gets us our second subarray in O(1) time.\n\n\n```\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& nums, int target) {\n\t//This part of code inserts every interval which sums up to target\n        vector<array<int,2>> iv ;\n        for(int s = 0, e = 0 , sum = 0 ; e < nums.size() ; ++e){\n            sum += nums[e] ;\n            while(sum > target) sum -= nums[s++];\n            if(sum == target) iv.push_back({s,e}) ;\n        }\n        \n\t\t// In interval , Store minimum upto index say i, from right to left\n        vector<int> minLen ;\n        for(int i = iv.size() - 1 ; i >= 0 ; --i ){\n            if(minLen.empty()) minLen.push_back(iv[i][1] - iv[i][0] + 1) ;\n            else minLen.push_back(min(minLen.back(),iv[i][1]-iv[i][0] + 1));\n        }\n        \n        reverse(begin(minLen),end(minLen)) ;\n        \n\t\t//choose index i as first subarray and search for other subarray using binary search and take minimum.\n        int mini = INT_MAX ;\n        for(int i = 0 ; i < iv.size() ; ++i ){\n            int l = iv[i][1] ;\n            int idx = upper_bound(begin(iv) + i + 1,end(iv),array<int,2>{l,INT_MAX}) - begin(iv) ;\n            if(idx < iv.size()) mini = min(mini,iv[i][1] - iv[i][0] + 1 + minLen[idx]) ;\n        }\n        return mini == INT_MAX ? -1 : mini ;\n    }\n};\n```
['C']