Easiest C++ Solution Using Unordered Map
\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        int rem=sum%p;\n        if(rem==0)\n            return 0;\nint mn=nums.size();\nunordered_map<int,int> m;\nsum=0;\nfor(int i=0;i<nums.size() ;i++){\nsum+=nums[i];\nint k=sum%p;\nif(k==rem)\n mn=min(mn,i+1);\n if(m.find(k-rem)!=m.end())\n     mn=min(mn,i-m[k-rem]);\n if(m.find(k-rem+p)!=m.end())\n mn=min(mn,i-m[p+k-rem]);\n     m[k]=i;            \n  }\n     if(mn>=nums.size())\n     return -1;\n\n return mn;\n    }\n};\n\n```
['Hash Table', 'Prefix Sum', 'C++']