C++ easy to understand DP O(N)
\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& arr, int target) {\n        int currsum=0;\n        int st=0;\n        int len=INT_MAX;\n     
```\nclass Solution {\npublic:\n    int minSumOfLengths(vector<int>& arr, int target) {\n        int currsum=0;\n        int st=0;\n        int len=INT_MAX;\n        vector<int> dp(arr.size(),INT_MAX);\n        int anslen=INT_MAX;\n        int i=0;\n        while(i<arr.size())\n        {\n            currsum+=arr[i];\n            while(currsum>target)\n            {\n                currsum-=arr[st];\n                st++;\n            }\n            if(currsum==target)\n            {\n                if(st>0 and dp[st-1]!=INT_MAX)\n                    len=min(len,dp[st-1]+i-st+1);\n                anslen=min(anslen,i-st+1);\n            }\n            dp[i]=anslen;\n            i++;\n        }\n        return len==INT_MAX?-1:len;\n    }\n};\n```
[]