PrefixSum Approch | 97%Beats
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:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\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 sum=0;\n        for(int i : nums){\n            sum = (sum+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 res = nums.length;\n        int pref=0;\n        for(int i=0; i<nums.length; i++){\n            pref = (pref+nums[i])%p;\n            int temp = (p-sum+pref)%p;\n            if(map.containsKey(temp)){\n                res = Math.min(res, i-map.get(temp));\n            }\n            map.put(pref, i);\n        }\n\n        return res>=nums.length? -1:res;\n    }\n}\n```
['Array', 'Hash Table', 'Prefix Sum', 'Java']