Simplified version in C++
Here is the original solution in Java: https://leetcode.com/problems/make-sum-divisible-by-p/solutions/854166/java-python-3-o-n-code-w-brief-explanation-analysi
Here is the original solution in Java: https://leetcode.com/problems/make-sum-divisible-by-p/solutions/854166/java-python-3-o-n-code-w-brief-explanation-analysis-and-similar-problems\n\uD83D\uDCAA\uD83D\uDE80Keep leetcoding! Keep improving!\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minSubarray(vector<int>& nums, int p) {\n        int remainder = 0, prefixSum = 0; \n        int n = nums.size(), minLen = n;\n        for (int num : nums) {\n            remainder = (remainder + num) % p; \n        }\n        cout <<remainder<<endl;\n        unordered_map<int,int> prefixSumToIndex;\n        prefixSumToIndex[prefixSum] = -1;\n        for (int i = 0; i < n; ++i) {\n            prefixSum = (prefixSum + nums[i]) % p;\n            prefixSumToIndex[prefixSum] = i;\n            int key = (prefixSum - remainder + p) % p;\n            //cout << i <<" "<< prefixSum<< " "<< key<<endl;\n            if (prefixSumToIndex.find(key) != prefixSumToIndex.end()) {\n                //cout << "here at"<<prefixSum<<" "<<key<<endl;\n                minLen = min(minLen, i - prefixSumToIndex[key]);\n            }\n        }\n        return minLen == n ? -1 : minLen;\n    }\n};\n```
['C++']