100% beats other solutions easy for begners
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n#include <vector>\n#include <unordered_map>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n    int minSubarray(vector<int>& nums, int p) {\n        int n = nums.size();\n        int total_sum = 0;\n        for (int num : nums) {\n            total_sum = (total_sum + num) % p;\n        }\n        if (total_sum == 0) return 0;\n\n        unordered_map<int, int> prefix_sum_map;\n        prefix_sum_map[0] = -1;\n        int current_sum = 0, min_length = n;\n\n        for (int i = 0; i < n; ++i) {\n            current_sum = (current_sum + nums[i]) % p;\n            int target = (current_sum - total_sum + p) % p;\n            if (prefix_sum_map.find(target) != prefix_sum_map.end()) {\n                min_length = min(min_length, i - prefix_sum_map[target]);\n            }\n            prefix_sum_map[current_sum] = i;\n        }\n\n        return min_length == n ? -1 : min_length;\n    }\n};\n\n```
['C++']