java solution
\n\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:\n Add your space complexity here, e.g. O(n) \n\n# Co
\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int n=nums.length, res=n, need=0, cur=0;\n        for( int num:nums)\n        {\n            need=(need+num)%p;\n        }\n        // need%=p;\n        Map<Integer, Integer>list=new HashMap<>();\n        list.put(0, -1);\n        for( int i=0; i<n; i++)\n        {\n            cur=(cur+nums[i])%p;\n            list.put(cur, i);\n            int we_need=(cur-need+p)%p;\n            res=Math.min(res, i-list.getOrDefault(we_need, -n));\n        }\n        return res<n ? res :-1;\n    }\n}\n```
['Java']