best explain
1.brute approach\n\npublic int minSumOfLengths(int[] arr, int target) {\n        if(arr==null||arr.length==0||target<1){\n            return -1;\n        }\n   
1.brute approach\n```\npublic int minSumOfLengths(int[] arr, int target) {\n        if(arr==null||arr.length==0||target<1){\n            return -1;\n        }\n        int[] dp=new int[arr.length];\n        List<Pair<Integer,Integer>> subarr=new ArrayList<>();\n        for(int i=0;i<arr.length;i++){\n            for(int j=0;j<=i;j++){\n                dp[j]=((i==j)?arr[i]:dp[j]+arr[i]);\n                if(dp[j]==target){\n                    subarr.add(new Pair(j,i));\n                }\n            }\n        }\n        int minSum=Integer.MAX_VALUE;\n        for(int i=0;i<subarr.size();i++){\n            Pair<Integer,Integer> pairI=subarr.get(i);\n            int start=pairI.getKey();\n            int end=pairI.getValue();\n            for(int j=i+1;j<subarr.size();j++){\n                Pair<Integer,Integer> pairJ=subarr.get(j);\n                int start1=pairJ.getKey();\n                int end1=pairJ.getValue();\n                if(end<start1||start>end1){\n                    minSum=Math.min(minSum,end-start+end1-start1+2);\n                }\n            }\n        }\n        return minSum==Integer.MAX_VALUE?-1:minSum;\n    }\n```\n\n2.opt\n    1.brute approach:\n       a:find the list for all of the  subarr which equals target.\n       b:then compute the sum of two subarr in the list,which need be uncrossed.\n       time complexity O(n^2)\n    2.how can we opt the brute approach?we can not opt it by caculating the two process separately.because  it has been optimum.in the case,we need merge the two process \n      into one process.\n    3.how to merge the two process?\n     c:for the subarr of start at i and sum equals target, we need find the min one subarr of start at (0,i-1) and sum equals target,the time complexity is O(n)\n     d:two subarr need be uncrossed.so for the subarr of start at i, we just need compare the subarr of  end at (0,i-1)\n     e:we can find it will be many duplicate computing  the sum of subarr in the process d.we can opt it by saving the sum of subarr,which use sum+=arr[i],dp[i]=sum.\n\n    ```\n    public int minSumOfLengths(int[] arr, int target) {\n        if(arr==null||arr.length==0||target<1){\n            return -1;\n        }\n        Map<Integer,Integer> dp = new HashMap<>();\n        dp.put(0,-1);\n        int sum=0;\n        int lsize=Integer.MAX_VALUE;\n        int result=Integer.MAX_VALUE;\n        for(int i=0;i<arr.length;i++){\n            sum+=arr[i];\n            dp.put(sum,i);\n        }\n        sum=0;\n        for(int i=0;i<arr.length;i++){\n            sum+=arr[i];\n            Integer left=dp.get(sum-target);\n            Integer right=dp.get(sum+target);\n            if(left!=null){\n                lsize=Math.min(lsize,i-left);\n            }\n            if(right!=null&&lsize!=Integer.MAX_VALUE){\n                result=Math.min(result,right-i+lsize);\n            }\n        }\n        return result==Integer.MAX_VALUE?-1:result;\n    }\n```
[]