Javascript Prefix Suffix array
For better understanding, Please visit:\nhttps://youtu.be/2PG3b067ogM?t=2\nif you like it. Please like and subscribe\n\n/**\n * @param {number[]} arr\n * @param
For better understanding, Please visit:\nhttps://youtu.be/2PG3b067ogM?t=2\nif you like it. Please like and subscribe\n```\n/**\n * @param {number[]} arr\n * @param {number} target [64,5,20,9,1,39]\n * @return {number}\n */\nvar minSumOfLengths = function(nums, target) {\n        let prefix = [],suffix=[],start=0,sum=0,min=0\n        for(let i=0;i<nums.length;i++){\n             sum += nums[i]\n                while(sum > target){\n                    sum -= nums[start++]\n                }\n            if(target == sum){\n                prefix[i] = min?Math.min(i-start+1,min):i-start+1\n                min = prefix[i]\n            }else{\n                prefix[i] = min\n            }\n        }\n        min = 0,sum = 0,start=nums.length-1\n        for(let i=nums.length-1;i>=0;i--){\n            while(sum > target){\n                    sum -= nums[start--]\n                }\n            if(target == sum){\n                suffix[i] = min?Math.min(start-i,min):start-i\n                min = suffix[i]\n            }else{\n                suffix[i] = min\n            }\n            sum += nums[i]\n        }\n    let ans = Number.MAX_VALUE\n    for(let i=0;i<nums.length;i++){\n        if(!prefix[i] || !suffix[i])continue\n        ans = Math.min(prefix[i]+suffix[i],ans)\n    }\n    return ans == Number.MAX_VALUE?-1:ans\n};\n\n\n```
['Dynamic Programming', 'Suffix Array', 'JavaScript']