Easy Prefix Sum Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\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```java []\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int n=nums.length;\n        int totalSum=0;\n        for(int num:nums){\n            totalSum=(totalSum+num)%p;\n        }\n        int target=totalSum%p;\n        if(target==0){\n            return 0;\n        }\n        HashMap<Integer,Integer> map=new HashMap<>();\n        map.put(0,-1); //if target is impossible\n        int currSum=0;\n        int minLen=n;\n        for(int i=0;i<n;i++){\n            currSum=(currSum+nums[i])%p;\n            int needed=(currSum-target+p)%p;//+p for -ve condition\n\n            if(map.containsKey(needed)){\n                minLen=Math.min(minLen,i-map.get(needed));\n            }\n            map.put(currSum,i);\n        }\n    return minLen==n?-1:minLen;\n    }\n}\n```
['Java']