MOD solution O(N) time complexity
Code\npython3 []\nclass Solution:\n    def minSubarray(self, nums: List[int], p: int) -> int:\n        total = sum(nums)\n        remainder = total % p\n       
# Code\n```python3 []\nclass Solution:\n    def minSubarray(self, nums: List[int], p: int) -> int:\n        total = sum(nums)\n        remainder = total % p\n        if remainder == 0:\n            return 0  \n        result = len(nums)\n        prefixsum = 0\n        dictremainder = {0: -1}\n        for i in range(len(nums)):\n            prefixsum += nums[i]\n            curremainder = prefixsum % p\n            target = (curremainder - remainder) % p\n            if target in dictremainder:\n                result = min(result, i - dictremainder[target])\n            dictremainder[curremainder] = i  \n        return result if result < len(nums) else -1\n```
['Python3']