Simple python3 solution | 382 ms - faster than 93.96% solutions
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nclass Solution:\n    def minSubarray(self, nums: List[int], p: int) -> int:\n        s = sum(nums) % p\n        if s == 0:\n            return 0\n\n        cum_sum = 0\n        d = {0: -1}\n        result = len(nums)\n        for j, elem in enumerate(nums):\n            cum_sum = (cum_sum + elem) % p\n            i = d.get((cum_sum - s) % p)\n            if i is not None:\n                result = min(result, j - i)\n            d[cum_sum] = j\n        \n        if result == len(nums):\n            return -1\n        return result\n```
['Hash Table', 'Math', 'Prefix Sum', 'Python3']