Prefix minimum array+binary search solution
```\nclass Solution:\n    def minSumOfLengths(self,a,k):\n        d=[]\n        s=0\n        a1={}\n        for i in range(len(a)):\n            s+=a[i]\n      
```\nclass Solution:\n    def minSumOfLengths(self,a,k):\n        d=[]\n        s=0\n        a1={}\n        for i in range(len(a)):\n            s+=a[i]\n            if s==k:\n                d.append([0,i])\n            elif s-k in a1:\n                d.append([a1[s-k]+1,i])\n            a1[s]=i\n        if len(d)==0:\n            return -1\n        e=[]\n        for i in range(len(d)):\n            e.append(d[i][1]-d[i][0]+1)\n        f=[]\n        h=e[0]\n        for i in range(len(e)):\n            h=min(h,e[i])\n            f.append(h)\n        o=-1\n        for i in range(1,len(d)):\n            i1=0\n            j1=i-1\n            p=-1\n            while(i1<=j1):\n                mid=(i1+j1)//2\n                if d[mid][1]>=d[i][0]:\n                    j1=mid-1\n                else:\n                    p=mid\n                    i1=mid+1\n            if p!=-1:\n                if o==-1:\n                    o=e[i]+f[p]\n                else:\n                    o=min(o,e[i]+f[p])\n        return o
['Dynamic Programming', 'Binary Tree']