🦚 Eazy Solution || Simple Mathematics !! || Simple & Concise Code || C++ Code Reference !
\n \n## " Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time. " ~Thomas A. Edison\n\n---\n# Intuition\
\n \n## " Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time. " ~Thomas A. Edison\n\n---\n# Intuition\n- Intuition Ko Mobile Addiction Hai !\n\n## Similar To This :\n- [560. Subarray Sum Equals K ](https://leetcode.com/problems/subarray-sum-equals-k/solutions/5664436/standard-approach-prefix-sum-slay-it-simple-concise-code-c-code-reference/)\n-  [523. Continuous Subarray Sum](https://leetcode.com/problems/continuous-subarray-sum/solutions/5669289/eazy-solution-simple-mathematics-simple-concise-code-c-code-reference/)\n- [974. Subarray Sums Divisible by K](https://leetcode.com/problems/subarray-sums-divisible-by-k/description/)\n# Approach\n- `Subarray Sum From i to j` : `P[j]-P[i]`\n    - Requirement : Sum of elements which are not in subarray() should be divisible by p :\n    - Total Array Sum = `T`;\n    - Sum of Subarray = `P[j]-P[i]`\n    - Sum of elements which are not in subarray : `(T-(P[j]-P[i]))`\n\n    - Required (Sum of elements which are not in subarray %p == 0) : `(T-(P[j]-P[i])) %p = 0 `\n    - `(T-P[j])%p = P[i]%k `\n    - Search `(T-P[j])%p` in map of `P[i]%k`\n    - `P[j] `Down there is S\n   \n![WhatsApp Image 2024-08-21 at 18.48.22_4580ec36.jpg](https://assets.leetcode.com/users/images/3da4099b-da60-4858-9442-1bd2bad18778_1724246695.8160481.jpeg)\n\n\n\n\n\n# Code\n```cpp [There You Go !!]\n\n    int minSubarray(vector<int>& A, int p) {\n        \n        int n=A.size(),mini=n;\n         long long T=0,S=0;\n\n        // Get Total Sum\n        for(auto & x: A)\n            T=(T+x)%p ;\n\n        // If Total sum of array is Divisible by p : ans 0\n        if(!T) return 0;\n\n        unordered_map<int,int>m;\n        m[0]=-1;\n        for(int i=0;i<n;i++)\n        {\n            S+=A[i];\n            \n            int r=((S-T)%p +p)%p;\n           if(m.find(r)!=m.end()) mini=min(mini,i-m[r]);\n\n            m[S%p]=i;\n\n        }\n        return mini==n? -1: mini;\n    }\n\n```\n\n# Guy\'s Upvote Pleasee !! (\u02E3\u203F\u02E3 \u035C)\n
['Array', 'Hash Table', 'Prefix Sum', 'C++']