[C++] Simple explanation
\nclass Solution {\npublic:\n    int minSubarray(vector<int>& nums, int p) {\n        if (nums.size() == 0)\n            return 0;\n        vector<int> pref(num
```\nclass Solution {\npublic:\n    int minSubarray(vector<int>& nums, int p) {\n        if (nums.size() == 0)\n            return 0;\n        vector<int> pref(nums.begin(),nums.end());\n        unordered_map <int,int> mp;\n        int n = nums.size();\n        int sum = nums[0];\n        int ans = n;\n        for (int i = 1; i < n; i++) {\n            pref[i] += pref[i-1]%p;\n            pref[i] %= p;\n            sum += nums[i]%p;\n            sum %= p;\n        }\n        if (sum%p == 0)\n            return 0;\n        int rem = sum%p;\n        mp[0] = -1;\n        for (int i = 0; i < n; i++) {\n            \n            int remNow = pref[i]%p;\n            if (mp.find((remNow-rem+p)%p) != mp.end())\n                ans = min(i-mp[(remNow-rem+p)%p], ans);\n            mp[remNow] = i;\n            \n        }\n        return ans == (n) ? -1 : ans;\n    }\n};\n\n\n/*\n    sum % p != 0\n    \n    sum % p  = ((sum - subsum)%p + subsum % p) % p\n    \n    but (sum - subsum)%p == 0 should be true\n    \n    so,\n    sum % p = subsum % p\n    \n    so find the smallest subarray whose remainder is (sum%p);\n    \n    How to do this in O(N)?\n    Try this problem: Subarray Sums Divisible by K\n\n*/\n```
[]