Python Solution O(n) | Sliding window + DP
Intuition\nUse sliding window to find the substring == target, and use dp to store min length substring (which is equal to target) so far till current index (ie
# Intuition\nUse sliding window to find the substring == target, and use dp to store min length substring (which is equal to target) so far till current index (ie. right pointer of sliding window) \n\nnow lets say ,if you find substring == target, then u take \n\nprevious_min_sm = min(previous_min_sum , current_substring_len + dp[left_pointer-1])\n\n\nHope you understood, me bad at explaining things in words\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        dp = [0]*len(arr)\n\n        sm = 0\n        l = 0\n        mn = len(arr)+1\n\n        for r in range(len(arr)):\n            sm += arr[r]\n\n            while l < r and sm > target:\n                sm -= arr[l]\n                l+=1\n\n            if sm == target:\n                dp[r] = min(dp[r-1],r-l+1) if dp[r-1] else r-l+1\n            \n                if dp[l-1]:\n                    mn = min(mn,dp[l-1]+r-l+1)\n        \n            else:\n                dp[r] = dp[r-1]\n    \n        return -1 if mn == len(arr)+1 else mn\n\n                \n            \n```
['Dynamic Programming', 'Sliding Window', 'Python3']