From e4893b7efe31cd455907c2c86c4932a0f7f42fd4 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:15:58 +0530 Subject: [PATCH] Create 1590. Make Sum Divisible by P --- 1590. Make Sum Divisible by P | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 1590. Make Sum Divisible by P 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