Easy Approach || Using hashmaps
\n\n# Code\n\nclass Solution {\npublic:\n    int minSubarray(vector<int>& nums, int p) {\n        long long int sum=0;\n        for(int i=0;i<nums.size();i++){\
\n\n# Code\n```\nclass Solution {\npublic:\n    int minSubarray(vector<int>& nums, int p) {\n        long long int sum=0;\n        for(int i=0;i<nums.size();i++){\n            sum+=nums[i];\n        }\n        \n        int rem=sum%p;\n        if(rem==0)return 0;\n\n        int ans=nums.size();\n        unordered_map<int,int>m;\n        sum=0;\n\n        for(int i=0;i<nums.size();i++){\n            sum+=nums[i];\n            int rem2=sum%p;\n\n            if(rem2==rem)\n                ans=min(ans,i+1);\n\n            if(m.find(rem2-rem)!=m.end()){\n                ans=min(ans,i-m[rem2-rem]);\n            }\n\n            if(m.find(p+rem2-rem)!=m.end()){\n                ans=min(ans,i-m[p+rem2-rem]);\n            }\n            m[rem2]=i;\n        }\n        if(ans>=nums.size())return -1;\n        return ans;\n        \n    }\n};\n\n\n```
['Hash Table', 'C++']