id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n vector<long> preFix = {nums[0]};\n vector<int> ans(nums.size());\n for(int i = 1; i < nums.size(); i++)\n {\n preFix.push_back(nums[i] + preFix[preFix.size() - 1]);\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n //preprocess: build prefixsum array for easier sum calculation\n vector<long long> prefix_sums = {nums[0]};\n for(int i = 1; i< nums.size(); i++){\n prefix_sums.push_back(nums[i] +...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans(nums.size(),-1);\n if(k>nums.size())return ans;\n vector<long> prefix{nums[0]};\n for(int i{1};i<nums.size();++i)\n {\n prefix.push_back(prefix.back()+nums[i]);...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<int> ans(nums.size(),-1);\n if(k>nums.size())return ans;\n vector<long> prefix{nums[0]};\n for(int i{1};i<nums.size();++i)\n {\n prefix.push_back(prefix.back()+nums[i]);...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long long> prefix = {nums[0]};\n\n for(int i = 1; i < nums.size(); i++) {\n prefix.push_back(prefix.back() + nums[i]);\n }\n\n vector<int> ans(nums.size(), -1);\n \n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector <double> total = {(double)nums[0]};\n int n = nums.size();\n vector <int> res(n);\n int i = 0, start = 0, end = 0;\n \n //printf(\" %d\\t\", total[0]);\n //Calculate ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long long int> sums;\n vector<int> ave;\n \n if(k == 0)\n return nums;\n \n if((2*k+1) > nums.size())\n {\n for(auto x:nums)\n {\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long long int> sums;\n vector<int> ave;\n \n if(k == 0)\n return nums;\n \n if((2*k +1) > nums.size())\n {\n for(auto x:nums)\n {\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long>prefix ={nums[0]};\n for(int i = 1; i<nums.size();i++)\n {\n prefix.push_back(prefix.back()+nums[i]);\n }\n \n // 1, 2,3,4\n // 1 3 6 10\n int ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n\n int n=nums.size();\n vector<long long int> pre(n),suff(n);\n\n pre[0]=nums[0];\n for(int i=1;i<n;i++)\n pre[i]=pre[i-1]+nums[i];\n \n \n suff[n-1]=nums[n-1];\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n if (k == 0) return nums;\n \n int n = nums.size();\n vector<long> prefix{nums[0]};\n for (int i = 1; i < n; i++) {\n prefix.push_back(prefix.back() + nums[i]);\n }\n ...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n \n vector<long long> prefix {nums[0]};\n size_t vs = nums.size();\n int avg;\n \n if (vs == 1) {\n if (k < 1) {\n return nums; \n } else {\n...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long int> presum(nums.size());\n vector<long int> postsum(nums.size());\n vector<long int> avg(nums.size());\n vector<int> ksum(nums.size());\n\n int size = nums.size();\n \...
2,211
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers, and an integer <code>k</code>.</p> <p>The <strong>k-radius average</strong> for a subarray of <code>nums</code> <strong>centered</strong> at some index <code>i</code> with the <strong>radius</strong> <code>k</code> is the...
3
{ "code": "class Solution {\npublic:\n vector<int> getAverages(vector<int>& nums, int k) {\n vector<long long int> prefixSum = {nums[0]};\n for (int i = 1; i < size(nums); i++)\n prefixSum.push_back(prefixSum.back() + nums[i]);\n int n = size(nums);\n vector<int> ans;\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int>&& successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n const int N = spells.size();\n sort(potions.begin(), potions.end());\n\n long long current = 0;\n auto cmp = [&current](const int cur, const long long v...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int>&& successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n const int N = spells.size();\n sort(potions.begin(), potions.end());\n\n // long long current = 0;\n /*\n auto cmp = [&current](const int cur, co...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(begin(potions), end(potions));\n for (int i{0}; i < spells.size(); ++i) {\n ssize_t min_int = (success + spells[i] - 1) / spells[i];\n const ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(\n vector<int>& spells, \n vector<int>& potions, \n long long success\n ) {\n\n const int n = spells.size();\n const int m = potions.size();\n\n ranges::sort(potions);\n \n vector<int> ans(...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(\n vector<int>& spells, \n vector<int>& potions, \n long long success\n ) {\n\n const int n = spells.size();\n const int m = potions.size();\n\n ranges::sort(potions);\n \n vector<int> ans(...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\n int lower_bound(vector<int>& potions, long long success, int s){\n int left = -1;\n int right = potions.size();\n long long target = (success + s - 1) / s; \n while(left + 1 < right){\n int mid = left + (right - left) / 2;\n if(potions...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\nSolution()\n {\n ios_base::sync_with_stdio(false); \n cin.tie(NULL); \n cout.tie(NULL);\n \n }\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n\n //brute force\n /* vector<int> pairs(...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n\n //brute force\n /* vector<int> pairs(spells.size()); \n for (int i = 0; i < spells.size(); i++) {\n int count = 0; \n for (int j = 0; j ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n /*\n spells i = strenght of ith spell\n potions j = strenght of jth potion\n spell and potion pair considered succcessful if spellsi * potionsj >= success...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(), potions.end());\n vector<int> res(spells.size(), 0);\n\n for (int i = 0; i < spells.size(); i++) {\n int l = 0, h = potions.size...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n=potions.size();\n vector<int>ans(spells.size(),0);\n sort(potions.begin(),potions.end());\n for(int i=0;i<spells.size();i++){\n int low=0...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n int findFirstPotion(vector<int>& potions, int m, int spell, long long success) {\n int left = 0, right = m-1;\n while(left <= right) {\n int mid = left + ((right-left)>>1);\n if((long long)potions[mid] * spell >= success) {\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(), potions.end());\n vector<int> pairs(spells.size());\n\n for(int i = 0; i < spells.size(); i++) {\n int l = 0, h = potions.size()...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution \n{\n\npublic:\n int bs(vector<int>& potions, long long spell, long long success)\n {\n int left = 0;\n int right = potions.size() -1;\n\n while(left<=right)\n {\n int mid = left + (right - left)/2;\n if((long long)potions[mid] * spell ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
0
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(),potions.end());\n vector<int> result(spells.size(),0);\n\n for (int i = 0; i < spells.size(); i++) {\n long long minPotion = (success...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(),potions.end());\n for(int i=0;i<spells.size();i++)\n {\n int left = 0,right = potions.size()-1;\n int curr_ind=-1;\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n = spells.size(), m = potions.size();\n vector<int> res(n);\n sort(potions.begin(), potions.end());\n printf(\"%d\", lower_bound(potions.begin(), pot...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n\n sort(potions.begin(), potions.end());\n vector<int> ans(spells.size());\n int n = potions.size();\n for(int i = 0; i < spells.size(); i++){\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int hash[spells.size()];\n for(int i=0;i<spells.size();i++){\n hash[i]=i;\n }\n sort(hash,hash+spells.size(),[&spells](int a,int b){\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n std::vector<int> res;\n\n std::ranges::sort(potions);\n\n for (int n : spells)\n {\n long long s = success / n;\n if (s * n < succes...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\n public:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions,\n long long success) {\n vector<int> ans;\n ranges::sort(potions);\n\n for (const int spell : spells)\n ans.push_back(potions.size() -\n firstIn...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\n public:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions,\n long long success) {\n vector<int> ans;\n ranges::sort(potions);\n\n for (const int spell : spells)\n ans.push_back(potions.size() -\n firstIn...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\n public:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions,\n long long success) {\n vector<int> ans;\n ranges::sort(potions);\n\n for (const int spell : spells)\n ans.push_back(potions.size() -\n firstIn...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\n public:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions,\n long long success) {\n vector<int> ans;\n ranges::sort(potions);\n\n for (const int spell : spells)\n ans.push_back(potions.size() -\n firstIn...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\nint a;\nvector<int>p;\nlong long x;\nint siz;\nint rec(int s,int e){\n if(s>e){\n // cout<<s<<\" \"<<e;\n return siz-1-e;\n }\n int mid=s+(e-s)/2;\n if((long long int)p[mid]*a>=x){\n return rec(s,mid-1);\n }\n else{\n return rec(mid+1...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n vector<int> Spairs(spells.size(),0);\n sort(potions.begin(),potions.end());\n for(int i=0;i<spells.size();i++){\n int right=potions.size()-1;\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(const vector<int>& spells, vector<int>& potions, long long success) {\n const int n = (int)spells.size(), m = (int)potions.size();\n vector<int> idx(n), ret(n);\n iota(idx.begin(), idx.end(), 0);\n ranges::sort(idx, [&sp...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int maxSpell = 0;\n for(int i=0; i<spells.size(); ++i){ //O(n)\n maxSpell = max(maxSpell, spells[i]);\n }\n vector<int> counts(maxSpell+1, 0);...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n\n sort(potions.rbegin(), potions.rend());\n const int nPotions = potions.size();\n\n const int nSpells = spells.size();\n vector<int> out(nSpells);\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n\n sort(potions.rbegin(), potions.rend());\n const int nPotions = potions.size();\n\n const int nSpells = spells.size();\n vector<int> out(nSpells);\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n\n sort(potions.rbegin(), potions.rend());\n const int nPotions = potions.size();\n\n const int nSpells = spells.size();\n vector<int> out(nSpells);\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(),potions.end());\n vector<int>pairs;\n int m=potions.size();\n for(int spell:spells){\n long long required=(success+spell-1...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions,\n long long success) {\n sort(potions.begin(), potions.end());\n vector<int> pairs;\n int m = potions.size();\n auto binary_search = [&](int spell...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n vector<int> res;\n sort(potions.begin(), potions.end()); // Sort the potions\n int size = potions.size();\n \n for (int spell : spells) {\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "// class Solution {\n// public:\n// vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n// vector<int> ans;\n// for(int i=0; i<spells.size(); i++){\n// int count = 0;\n// int prod = success/spells[i];\n// for(i...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(),potions.end());\n vector<int> ans;\n for(int i:spells){\n int left=0;\n int right=potions.size();\n while(l...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n int n=spells.size();\n int m=potions.size();\n sort(potions.begin(),potions.end());\n vector<int> v;\n for(int a:spells){\n long long ne...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
1
{ "code": "#include \"bits/stdc++.h\"\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n \n sort(potions.begin(),potions.end());\n int n=spells.size();\n int m=potions.size();\n\n vect...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
2
{ "code": "class Solution {\npublic:\n\n\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) \n {\n sort(potions.begin(),potions.end());\n vector<int> ans;\n long long i=0,n=potions.size();\n for(i=0;i<spells.size();i++)\n {\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
2
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(),potions.end());\n vector<int>v;\n for(auto i : spells){\n\n int l = lower_bound(potions.begin(),potions.end(), (double)success / ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
3
{ "code": "// class Solution {\n// public:\n// vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n// vector<int> ans;\n// for(int i=0; i<spells.size(); i++){\n// int count = 0;\n// int prod = success/spells[i];\n// for(i...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
3
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(),potions.end());\n vector<int>v;\n // unordered_map<int,int>map;\n for(auto i : spells){\n // if(map.find(i) != map.end()){...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
3
{ "code": "class Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success)\n {\n vector<int> ans;\n\n sort(potions.begin(), potions.end());\n\n for (auto& i : spells)\n {\n double num = (double)success / i;\n ...
2,392
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</su...
3
{ "code": "#pragma GCC optimize(\"Ofast,no-stack-protector\")\n#pragma GCC optimize(\"no-math-errno,unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n sort(potions.begin(...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
0
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n int n = cookies.size();\n int ans = INT_MAX;\n \n auto dfs = [&](auto &&self, int mask, int j, int unfairness, int current_fairness) -> void {\n if (mask == (1 << n) - 1 || j == k) {...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
0
{ "code": "class Solution {\npublic:\n void solve(vector<int>&cookies,int k,vector<int>&val,int &ans,int ind){\n if(ind<0){\n ans=min(ans,*max_element(val.begin(),val.end()));\n return;\n }\n for(int i=0;i<k;i++){\n val[i]+=cookies[ind];\n solve(cook...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
0
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n vector<int> distr(k, 0);\n int res = INT_MAX;\n recurse(cookies, 0, distr, k, res);\n return res;\n }\n\n void recurse(auto &cookies, int idx, auto &distr, int k, int &res) {\n if(...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
0
{ "code": "class Solution {\n int unfair_track = 1e9;\nprivate:\n void check_fairness(int bag, vector<int>& cookies, vector<int>& cookie_count, int k){\n if(bag == cookies.size()){\n unfair_track = min(unfair_track, *max_element(cookie_count.begin(), cookie_count.end()));\n return;\...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
0
{ "code": "class Solution {\npublic:\n int fn(int index, vector<int> &v, vector<int>& cookies) {\n if (index == cookies.size()) return *max_element(v.begin(), v.end());\n int ans = 1e9;\n for (int i = 0; i < v.size(); i++) {\n v[i] += cookies[index];\n ans = min(ans, fn(i...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
0
{ "code": "class Solution {\npublic:\n void solve(int i,int n,vector<int>&c,int k,vector<int>&sum,int &ans){\n if(i>=n){\n ans=min(ans,*max_element(sum.begin(),sum.end()));\n return ;\n\n }\n for(int j=0;j<k;j++){\n sum[j]+=c[i];\n solve(i+1,n,c,k,su...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
0
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n int n = cookies.size();\n int ans = INT_MAX;\n \n auto dfs = [&](auto &&self, int mask, int j, int unfairness, int current_fairness) -> void {\n if (mask == (1 << n) - 1 || j == k) {...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
1
{ "code": "class Solution {\npublic:\nint minele=INT_MAX;\nint backtrack(int index,vector<int>&v,vector<int>& cookies,int k,int n)\n{ \nif(index==n)\n{\n return *max_element(v.begin(),v.end());\n}\nfor(int i=0;i<k;i++){\nv[i]+=(cookies[index]);\nminele=min(minele,backtrack(index+1,v,cookies,k,n));\nv[i]-=cookies[ind...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
1
{ "code": "class Solution {\npublic:\nint minele=INT_MAX;\nvoid backtrack(int index,vector<int>&v,vector<int>& cookies,int k,int n)\n{ \nif(index==n)\n{\n int mx=*max_element(v.begin(),v.end());\n minele=min(minele,mx);\n return;\n}\nfor(int i=0;i<k;i++){\nv[i]+=(cookies[index]);\nbacktrack(index+1,v,cookies,k,n);\n...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n typedef vector<int> int_arr;\n float target;\n int u = INT_MAX;\n void bt(int_arr& cookies, int_arr& child, int idx) {\n if (idx == cookies.size()) {\n int max_u = INT_MIN;\n for (int c : child) {\n max_u = max(max_u, c);\n...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "#define rep(i,a,b) for(int i=a;i<b;i++)\n\nclass Solution {\n bool isPossible(int idx, int unfairness, vector<int>& cookies, vector<long long>& children) {\n if (idx == cookies.size()) {\n return *max_element(children.begin(), children.end()) <= unfairness;\n }\n\n rep(i,...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\n int unfair_track = 1e9;\nprivate:\n void check_fairness(int bag, vector<int>& cookies, vector<int>& cookie_count, int k, int curr_max) {\n if (bag == cookies.size()) {\n unfair_track = min(unfair_track, curr_max);\n return;\n }\n\n for (in...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n int n = cookies.size();\n vector<int> sum(1 << n, 0);\n \n // Calculate sum for every subset of cookies\n for (int mask = 0; mask < (1 << n); ++mask) {\n for (int i = 0; i < n...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n int n = cookies.size();\n vector<vector<int>>dp(k+1,vector<int>((1<<n)+1,1e9));\n vector<int>sum((1<<n));\n for(int mask = 0; mask < (1<<n); mask++){\n for(int i = 0; i < n; i++){\n ...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& tasks, int K) {\n int n = tasks.size();\n vector<vector<int>> dp((1<<n),vector<int>(K,0));\n vector<int> sum((1<<n),0);\n for(int i = 1;i<(1<<n);i++){\n int s = 0,p = 1;\n for(int j = 0;j<n;j...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n int n = cookies.size();\n vector<int> sum(1<<n,0);\n\n for(int mask = 0;mask < (1 << n);mask++){\n for(int i = 0;i < n;i++){\n if(mask & (1 << i)){\n sum[m...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\nprivate :\n vector<vector<int>> dp;\n vector<int> sum;\n\n int solve(int mask,int children){\n if(dp[mask][children] != -1) return dp[mask][children];\n\n if(children == 1){\n return sum[mask];\n }\n int ans = INT_MAX;\n for(int subma...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n sort(cookies.rbegin(), cookies.rend());\n int cnt[k];\n memset(cnt, 0, sizeof cnt);\n int n = cookies.size();\n int ans = 1 << 30;\n function<void(int)> dfs = [&](int i) {\n ...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n sort(cookies.rbegin(), cookies.rend());\n int n = cookies.size();\n vector<int> child(k);\n int result = INT_MAX;\n function<void(int)> dfs = [&](int index){\n if(index>=n)\n ...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int distributeCookies(vector<int>& cookies, int k) {\n int s=1,e=1e6;\n int n=cookies.size();\n for(int i=0;i<n;i++){\n s=max(s,cookies[i]);\n }\n int ans=0;\n while(s<=e){\n int mid=s+(e-s)/2;\n vecto...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n int min_unfairness = INT_MAX;\n void distributeAllCookies(vector<int>& cookies, int idx, vector<int>& children, int most_cookies) {\n if (idx == cookies.size()) {\n min_unfairness = min(min_unfairness, most_cookies);\n return;\n }\n ...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "\n\nint ans;\n\nvoid solve(int i, const std::vector<int> &bags, std::vector<int> &distr, int k)\n{\n if(i == bags.size())\n {\n int maxm = INT_MIN;\n for(int j = 0; j < k; j++)\n {\n if(!distr[j])\n return;\n maxm = std::max(maxm, distr[j]);\n...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n \n // Function to calculate the unfairness using dynamic programming\n int unfairness(vector<int>& cookies, int n, int k, int bagMask) {\n // If the subproblem has already been solved, return the pre-calculated value\n if (dp[k...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n \n // Function to calculate the unfairness using dynamic programming\n int unfairness(vector<int>& cookies, int n, int k, int bagMask) {\n // If the subproblem has already been solved, return the pre-calculated value\n if (dp[k...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\nprivate:\n void solve(vector<int>& cookies, int i, int &k, int &size, vector<int> sum, int &mini){\n\n\n if (i >= size){\n int unfair = INT_MIN;\n for (int j = 0; j < k; j++){\n unfair = max(unfair, sum[j]);\n }\n if (un...
1,418
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the s...
3
{ "code": "class Solution {\npublic:\n\n void solve(int ind,int n,vector<int>& nums,vector<int>& childGet,int k,int &ans)\n {\n if(ind==n)\n {\n int maxi=INT_MIN;\n for(int i=0;i<k;i++)\n {\n maxi=max(maxi,childGet[i]);\n }\n ans...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n // then we need to do this for all of the ones seen\n sort(ideas.begin(),ideas.end());\n\n vector<vector<int>> bar(26,vector<int>(26));\n\n bitset<26...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n \n \n \n long long int ans=0;\n vector<int> count(26,0);\n unordered_map<string,int> mp; \n vector<vector<int>> arr(26,vector<int> (26,0));\n \n for(auto s:ideas)...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n int n = ideas.size();\n unordered_map<string, int> dc;\n vector<vector<int>> ccnt(26, vector<int>(26));\n for (int i=0; i<n; ++i) dc[ideas[i].substr(1)] |= 1 << (ideas[i].front() - 'a');\n a...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\n unordered_map<string, bitset<26>> umsv;\n vector<bitset<26>> vvc;\n vector<long long> single_stuff;\n long long sum;\n\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n // umsv.reserve(10000);\n ...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\n unordered_map<string, bitset<26>> umsv;\n vector<bitset<26>> vvc;\n long long single_stuff[26] = {0};\n long long sum;\n\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n // single_stuff = {0};\n ...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\n long long solve(vector<string> &a, vector<string> &b){\n // unordered_set<string> st;\n // for(auto &it:a) st.insert(it);\n // for(auto &it:b) st.insert(it);\n // return a.size() + b.size() - st.size();\n\n long long ans = 0;\n int n = a.size(...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\npublic:\n long long getNames(unordered_set <string>& a, unordered_set <string>& b) {\n long long cnt = 0;\n for(auto& it: a) {\n if(b.count(it) > 0) {\n cnt++;\n }\n }\n\n return 2*(a.size()-cnt)*(b.size()-cnt);\n }\n\n long long distinc...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n vector<unordered_set<string>>v(26);\n for(auto i:ideas){\n string s=i;\n v[i[0]-'a'].insert(s.substr(1,s.length()-1));\n }\n long long ans=0;\n for(int i=0;i<26;i++){\n...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n vector<unordered_set<string>>count(26);\n for(auto &idea: ideas){\n count[idea[0]-'a'].insert(idea.substr(1));\n }\n long ans = 0;\n for(int i=0;i<26;i++){\n for(int j=...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n vector<unordered_set<string>>count(26);\n for(auto &idea: ideas){\n count[idea[0]-'a'].insert(idea.substr(1));\n }\n long ans = 0;\n for(int i=0;i<26;i++){\n for(int j=...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\n public:\n long long distinctNames(vector<string>& ideas) {\n long ans = 0;\n // suffixes[i] := the set of strings omitting the first letter, where the\n // first letter is ('a' + i)\n vector<unordered_set<string>> suffixes(26);\n\n for (const string& idea : ideas)\n ...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
0
{ "code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n //without considering the first letter find number of distinct strings mark the number of words each of them correspond to\n //each of these first letters(corresponding to same body) cannot be swapped with each othe...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
1
{ "code": "class Solution {\npublic:\n /*\n\n We can group the suffixes of all words in ideas by their initials, \n take apple as an example, we store pple in a set marked with key as a.\n\n For two groups with initial letters a and b, if a suffix\n is contained by both groups, \n then swapping a + ...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
1
{ "code": "class Solution {\npublic:\n \n long long distinctNames(vector<string>& ideas) {\n //unordered map and set because finding an element will be of O(1)\n unordered_map<char,unordered_set<string>> m;\n long long res=0;\n //creating the map with 1st letter as key and the rest ...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
1
{ "code": "#include <bits/stdc++.h>\n#ifdef DEBUG\n#include \"debug.h\"\n#else\n#define dbg(x...)\n#endif\nusing namespace std;\nusing ll = long long;\n\nclass Solution {\npublic:\n ll distinctNames(vector<string>& ideas) {\n\t\tunordered_set<string> st(ideas.begin(), ideas.end());\n\t\tvector<vector<int>> num_goo...
2,390
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p> <ol> <li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su...
1
{ "code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string> fs;\n for (const auto& s : ideas) {\n fs.insert(s);\n }\n\n vector<vector<int>> cnt(26, vector<int>(26));\n\n for (const auto& s : ideas) {\n stri...