[Java] O(N) time solution with hashmap
\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int n = nums.length, sum = 0;\n        for (int i = 0; i < n; i++) sum = (sum + num
```\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int n = nums.length, sum = 0;\n        for (int i = 0; i < n; i++) sum = (sum + nums[i]) % p;\n        \n        if (sum == 0) return 0;\n        \n        Map<Integer, Integer> map = new HashMap<>();\n        map.put(0, -1);\n        \n        int curSum = 0, answer = n;\n        for (int i = 0; i < n; i++) {\n            curSum = (curSum + nums[i]) % p;\n            int diff = (curSum - sum + p) % p;\n            \n            if (map.containsKey(diff)) {\n                int length = i - map.get(diff);\n                answer = Math.min(answer, length);\n            }\n            \n            map.put(curSum, i);\n        }\n        \n        return answer == n ? -1 : answer;\n    }\n}\n```
[]