Python easy solution
class Solution:\n\n    def minSubarray(self, nums: List[int], p: int) -> int:\n        ans = float("inf")\n        s = sum(nums)%p # remainder of the sum\n     
class Solution:\n\n    def minSubarray(self, nums: List[int], p: int) -> int:\n        ans = float("inf")\n        s = sum(nums)%p # remainder of the sum\n        d = {0:-1}\n        cum = 0\n        if s == 0:\n            return 0\n        for i in range(len(nums)):\n            cum+=nums[i]\n            r = cum%p\n            if (r-s)%p in d: # find the index that if we delete all the elements between index:i, we will have a valid answer \n                ans = min(ans, i-d[(r-s)%p])\n            d[r] = i\n        return ans if ans<len(nums) else -1
['Python']