Which subarray you should remove?? Detailed Explanation, Typescript
Let\'s first find out which subarray we should remove -:\n\n\n\nfor smallest subarray we can use Map to store most recent prefixSum remainder.\n\n\nfunction min
**Let\'s first find out which subarray we should remove -:**\n![image](https://assets.leetcode.com/users/images/66df4e56-08b3-4259-8196-81175d345a76_1622281342.3829982.jpeg)\n\n\n**for smallest subarray we can use Map to store most recent prefixSum remainder.**\n\n```\nfunction minSubarray(nums: number[], p: number): number {\n    \n    let mp=new Map(),\n        ans:number=nums.length,\n        rem:number=0,\n        curr:number=0;\n    for (let v of nums){\n        rem+=v;\n    }\n    rem=rem%p;\n    if (rem==0){\n        return 0;\n    }\n    mp.set(0,-1);\n    for (let i=0;i<nums.length;i++){\n        curr+=nums[i];\n        curr=curr%p;\n        mp.set(curr,i);\n        if (mp.has((curr-rem+p)%p)){\n            ans=Math.min(ans,i-mp.get((curr-rem+p)%p));\n        }\n    }\n    \n    return ans>=nums.length?-1:ans;\n\n};\n```\n\n
[]