C++ || One pass | with comments
\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& arr, int target) {\n        int size=arr.size(),sum=0,ans=INT_MAX;\n        unordered_map<int,
```\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& arr, int target) {\n        int size=arr.size(),sum=0,ans=INT_MAX;\n        unordered_map<int,int>mp;\n        // to handle corner cases,you can say it is also one pass,but i am just ignoring it :P\n        arr.insert(arr.begin(),0);\n        size++;\n        // trackmin[i] will give you the minimum length of subarray till i(included) ,whose sum is equals to target\n        vector<int>trackmin(size,INT_MAX);\n        mp[0]=0;\n        for(int i=1;i<size;i++){\n           sum+=arr[i];\n            // if we find subarray whose sum== target\n            if(mp.find(sum-target)!=mp.end()){\n                // calculate surrent length\n                int curlen=i-mp[sum-target];\n                // get previous length from trackmin\n                int premin=trackmin[mp[sum-target]];\n                if(premin!=INT_MAX)\n                    ans=min(ans,curlen+premin);\n                // update trackmin[i]\n                trackmin[i]=min(curlen,trackmin[i-1]);\n            }\n            else\n               trackmin[i]=trackmin[i-1];\n            mp[sum]=i;\n        }\n        return ans==INT_MAX?-1:ans;\n    }\n};\n```\nDo **UPVOTE** is it helps :)
['C']