C++ O(N) with some explanation and example
Find smallest subarray that the sum is X, which is remainder + p*integer, integer >= 0\nAnd we know, X + (p - remainder) = p*(integer + 1)\nSo use presum and ha
Find smallest subarray that the sum is X, which is ```remainder + p*integer, integer >= 0```\nAnd we know, X + ```(p - remainder)``` = ```p*(integer + 1)```\nSo use presum and hashmap\nif ```( presum +  (p - remainder) ) % p``` is found in hashtable the subarray is found\nFor **edge case** first presum, I add {0, -1} to hashmap\n\nExample: ```[26,19,11,14,18,4,7,1,30,23,19,8,10,6,26,3], p = 26```\nFirst get presum array is\n```[0,19,4,18,10,14,21,22,0,23,16,24,8,14,14,17]```\n**Remainder** is 17, so we find the smallest subarray that sum is **17 + 26\\*n**\nThe difference is **p - remainder** = 26 - 17 = 9\nPresum of index 4 is 10, ```10 + 9 = 19``` can be found in index 1, then the result is 4 - 1 = 3\nWe see original input ```18 + 14 + 11 = 43 = 17 + 26*1```\n=> ```43 + 9 = 26*2``` \n```\nclass Solution {\npublic:\n    int minSubarray(vector<int>& nums, int p) {\n        int sum = 0;\n        int n = nums.size();\n        unordered_map<int, int> table;\n        table[0] = -1;\n        for(int i = 0; i < n; i++)  {\n            sum = (sum + nums[i])%p;\n            nums[i] = sum;\n        }\n        if(sum == 0) return 0;\n        int diff = p - sum;\n        int res = INT_MAX;\n        for(int i = 0; i < n; i++) {\n            int num = (nums[i] + diff)%p;\n            if(table.count(num))\n                res = min(res, i - table[num]);\n            table[nums[i]] = i;\n        }\n        if(res == n) return -1;\n        return res == INT_MAX? -1 : res;\n    }\n};\n```
['C']