Java O(n) 12ms
Storing all the index of sub arrays with sum equals to target using sliding window.\n dp[en] = st, where st, en represents the start and end of the sub array re
* Storing all the index of sub arrays with sum equals to target using sliding window.\n* `dp[en] = st`, where st, en represents the start and end of the sub array respectively.\n* ans = Math.min(ans, length of curr subarray **+** min length of subarray with index < start of curr subarray) => `Math.min(ans, (i - dp[i] + 1) + dp[dp[i]-1])`\n* Updating dp[i] with min length encountered till index i => `dp[i] = Math.min(dp[i-1], i-dp[i] + 1)`\n\n\n```\npublic int minSumOfLengths(int[] arr, int target) {\n        int n = arr.length;\n        int []dp = new int[n+1];\n        int st = 0;\n        int en = 0;\n        int sum = 0;\n        int ans = Integer.MAX_VALUE;\n        Arrays.fill(dp, Integer.MAX_VALUE);\n        while(en < n){\n            sum += arr[en];\n            while(st <= en && sum > target){\n                sum -= arr[st++];\n            }\n            if(sum == target){\n                dp[en+1] = st+1;\n            }\n            en ++;\n        }\n        for(int i=1;i<=n;i++){\n            if(dp[i] != Integer.MAX_VALUE){\n                if(dp[dp[i]-1] != Integer.MAX_VALUE){\n                    ans = Math.min(ans, dp[dp[i]-1] + i - dp[i] + 1);\n                }\n                dp[i] = Math.min(i-dp[i]+1, dp[i-1]);\n            }else{\n                dp[i] = dp[i-1];\n            }\n        }\n        if(ans == Integer.MAX_VALUE){\n            return -1;\n        }\n        return ans;\n    }\n```
[]