HashMap approach beats 95%
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int minSubarray(int[] nums, int p) {
    long sum=0;
    for(int i : nums){
      sum+=i;}
    long pref=0;
    int min=nums.length;
    int rem =(int) (sum % p);
    HashMap<Integer, Integer> ocr = new HashMap<>();
    if(sum%p == 0)return 0;
    ocr.put(0,-1);
    for(int i=0;i<nums.length;i++){
      pref+=nums[i];
      int remrn = (int)(pref % p);
      int remtg = (remrn - rem +p)%p;
      if(ocr.containsKey(remtg)){
        min=Math.min(min,i-ocr.get(remtg));}
      ocr.put(remrn,i);}
if(min==nums.length)return -1;
else return min;}}
```
['Java']