Java Clean Solution
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
# 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```java []\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int n = nums.length;\n\n        long sum = 0;\n        for (int num : nums) {\n            sum += num;\n        }\n\n        // Edge case\n        if (sum % p == 0) {\n            return 0;\n        }\n        if (sum < p) {\n            return -1;\n        }\n\n        Map<Long, Integer> map = new HashMap<>();\n        map.put(0l, -1);\n\n        long rem = sum % p;\n        sum = 0;\n        int res = n;\n        for (int i = 0; i < n; i++) {\n            sum += nums[i];\n            sum %= p;\n\n            long rem_ = sum - rem;\n            if (rem_ < 0) {\n                rem_ += p;\n            }\n\n            Integer val = map.get(rem_);\n            if (val != null) {\n                res = Math.min(res, i - val);\n            }\n            map.put(sum, i);\n        }\n        return res == n ? -1 : res;\n    }\n}\n```
['Array', 'Hash Table', 'Prefix Sum', 'Java']