diff --git a/1590. Make Sum Divisible by P b/1590. Make Sum Divisible by P new file mode 100644 index 0000000..a4bcf89 --- /dev/null +++ b/1590. Make Sum Divisible by P @@ -0,0 +1,36 @@ +typedef long long ll; +class Solution { +public: + int minSubarray(vector& nums, int p) { + /* + 3 1 4 2 totalsum=10 + remove 3 or 31 or 314 + remove 1 or 14 or 142 + remove 4 or 42 + remove 2 + 0 3 1 4 2 + ps[0 3 4 8 10] + brute force O(N*2); + how to do it nlogn or n + if on subtracting from sum a number which has same remainder when%p + thats the ans + now question becomes finding subarrya with sum as sum%p + */ + int n=nums.size(); + ll totalsum=0; + for(auto& i:nums)totalsum+=i; + if(totalsum%p==0)return 0; + ll rem=totalsum%p; + unordered_mapmp; + ll sum=0;int ans=n; + mp[0]=-1; + for(int i=0;i