Java
\n\n# Code\njava []\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        \n        long sum = 0;\n        for (int i = 0; i < nums.length
\n\n# Code\n```java []\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        \n        long sum = 0;\n        for (int i = 0; i < nums.length; i++) sum += nums[i];\n        if (sum % p == 0) return 0;\n\t\t\n\t\tint requiredRem = (int) (sum % p);\n        HashMap<Integer, Integer> rem = new HashMap<>();\n        rem.put(0, -1);\n        \n        sum = 0;\n        int res = nums.length;\n        for (int i = 0; i < nums.length; i++) {\n            sum += nums[i];\n            int curRem = (int) (sum % p);\n        \n            int searchFor = curRem - requiredRem;\n            if (searchFor < 0) searchFor += p;\n            if (rem.containsKey(searchFor))\n                res = Math.min(res, i - rem.get(searchFor));\n\n            \n            rem.put(curRem, i);\n        }\n        return (res == nums.length) ? -1 : res;\n    }\n}\n```
['Java']