id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int freq[50001]={0};\n int minN=50000, maxN=0;\n\n for(int x: nums){\n freq[x]++;\n minN=min(minN, x);\n maxN=max(maxN, x);\n }\n int count=0, sum=0;\n\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\nint reductionOperations(vector<int>& nums) {\n int freq[50001]={0};\n int minN=50000, maxN=0;\n for(int x: nums){\n freq[x]++;\n minN=min(minN, x);\n maxN=max(maxN, x);\n }\n int count=0, sum=0;\n for(int ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int freq[50001]={0};\n int minN=50000, maxN=0;\n\n for(int x: nums){\n freq[x]++;\n minN=min(minN, x);\n maxN=max(maxN, x);\n }\n int count=0, sum=0;\n\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int freq[50001]={0};\n int minN=50000, maxN=0;\n\n for(int x: nums){\n freq[x]++;\n minN=min(minN, x);\n maxN=max(maxN, x);\n }\n int count=0, sum=0;\n\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int reductionOperations(std::vector<int>& nums) ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int n=nums.size();\n int count=0;\n sort(nums.begin(),nums.end());\n if(n==1)\n return 0;\n\n for(int i=0;i<n;i++){\n while(nums[i]==nums[i+1]){\n i++;\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int s=nums.size();\n\n int operations=0;\n\n int last=-1;\n int current_sum=0;\n for(int i=s-1;i>=0;i--)\n {\n\n if(last==nums[i])\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n int count =0;\n for(int i=n-1;i>0;i--){\n if(nums[i]==nums[i-1]){\n continue;\n }\n else\n count+=n-i;\n\n }\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& v) {\n sort(v.begin(),v.end());\n int c=0;\n int x=v.size();\n for(int i=x-1;i>0;i--){\n if(v[i-1]<v[i]){\n c+=(x-i);\n }\n // cout<<c<<endl;\n }\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
0
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int operationNO =0;\n sort(nums.begin(), nums.end());\n for(int i = nums.size()-1 ; i>=1 ; i--){\n if(nums[0]==nums[i]){\n break;\n \n }\n else i...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
1
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& v) {\n sort(v.begin(),v.end());\n int c=0;\n int x=v.size();\n for(int i=x-1;i>0;i--){\n if(v[i-1]<v[i]){\n c+=(x-i);\n }\n cout<<c<<endl;\n }\n r...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
2
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int s=nums.size();\n\n int operations=0;\n\n int last=-1;\n int current_sum=0;\n for(int i=s-1;i>=0;i--)\n {\n\n if(last==nums[i])\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
2
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n sort(nums.rbegin(),nums.rend());\n int ans = 0, cnt = 1, n = nums.size();\n for(int i=1;i<n;i++) {\n if(nums[i-1] != nums[i]) {\n ans += cnt;\n }\n cnt++;\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
2
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n sort(nums.rbegin(), nums.rend());\n int total = 0;\n for (int i = 0; i < nums.size() - 1; i++) {\n if (nums[i] > nums[i + 1]) {\n total += i + 1;\n }\n }\n r...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
2
{ "code": "class Solution {\npublic:\n\n int reductionOperations(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int total = 0, temp = 0;\n vector<int> vals;\n for(int i = 0; i < nums.size(); i++)\n {\n if(i == 0 || nums[i] != nums[i - 1])\n {\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n priority_queue<int> pq;\n for(int i : nums)\n {\n pq.push(i);\n }\n int ans=0;\n int prev=0;\n while(!pq.empty())\n {\n int count=0;\n int x...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n // O(max(N, max_number)) time - O(max_number) space\n int reductionOperations(std::vector<int>& nums) {\n // compute frequency of every number\n int max_number{\n *std::max_element(nums.begin(), nums.end())}; // O(N) time\n std::vector<int> ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n // O(max(N, max_number)) time - O(max_number) space\n int reductionOperations(std::vector<int>& nums) {\n // compute frequency + how many different numbers\n int diff_num{0};\n int max_number{*std::max_element(nums.begin(), nums.end())};\n std::...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n // O(max(N, max_number)) time - O(max_number) space\n int reductionOperations(std::vector<int>& nums) {\n // compute frequency + # of unique nums\n int unique_nums{0};\n int max_number{*std::max_element(nums.begin(), nums.end())};\n std::vector<...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(std::vector<int>& nums) {\n int unique_nums{0};\n int max_number{*std::max_element(nums.begin(), nums.end())};\n std::vector<int> count(max_number + 1);\n for (auto const& number : nums)\n if (++count[number] == 1...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int smallest = INT_MAX;\n for(int i=0;i < nums.size();i++){\n smallest = min(smallest,nums[i]);\n }\n int total = nums.size();\n int highest = smallest;\n for(int i=0;i < nums....
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int smallest = INT_MAX;\n for(int i=0;i < nums.size();i++){\n smallest = min(smallest,nums[i]);\n }...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int ops = 0;\n int maxSize = 0;\n for(int i=0;i<nums.size();++i)\n maxSize = max(maxSize, nums[i]);\n \n vector<int> count(maxSize+1);\n for(int i : nums)\n count[i]...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int k = (int)5e4 + 1;\n vector<int> count(k);\n int min_val = INT_MAX;\n int max_val = INT_MIN;\n for (auto n : nums) {\n count[n] += 1;\n min_val = min(min_val, n);\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int n = nums.size(), sum = 0, mx = -1;\n vector<int> fq(50004), unique;\n sort(nums.begin(), nums.end());\n \n for(int i = 0; i < n; i++) {\n if(fq[nums[i]] == 0) {\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(auto ele:nums)mp[ele]++;\n sort(nums.begin() , nums.end());\n int ind = 0, min = nums[0],n = nums.size();\n while(ind<n and nums[ind] == min) ind++;\n if(i...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "// Not mine\nclass Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(auto ele:nums)mp[ele]++;\n sort(nums.begin() , nums.end());\n int ind = 0, min = nums[0],n = nums.size();\n while(ind<n and nums[ind] == min) ind++;\...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(auto ele:nums)mp[ele]++;\n sort(nums.begin() , nums.end());\n int ind = 0, min = nums[0],n = nums.size();\n while(ind<n and nums[ind] == min) ind++;\n if(i...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(auto ele:nums)mp[ele]++;\n sort(nums.begin(),nums.end());\n int ind = 0,min = nums[0],n = nums.size();\n while(ind<n && nums[ind]==min) ind++;\n if(ind>=n)...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(std::vector<int>& nums) {\n std::vector<int> unique;\n unique.reserve(nums.size());\n std::unordered_map<int, int> map;\n for (int i = 0; i < nums.size(); ++i) {\n auto it = map.find(nums[i]);\n if (it ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(std::vector<int>& nums) {\n std::vector<int> unique;\n unique.reserve(nums.size());\n std::unordered_map<int, int> map;\n for (int i = 0; i < nums.size(); ++i) {\n auto it = map.find(nums[i]);\n if (it ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(std::vector<int>& nums) {\n std::vector<int> unique;\n unique.reserve(nums.size());\n std::unordered_map<int, int> map;\n for (int i = 0; i < nums.size(); ++i) {\n auto it = map.find(nums[i]);\n if (it ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n map<int, int> mpp;\n for(int i=0;i<nums.size();i++){\n mpp[nums[i]]++;\n }\n int count=0;\n\n while(!(mpp.size()==1)){\n int largest=mpp.rbegin()->first;\n int f...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n map<int,int> hsh;\n for(auto x : nums) hsh[x]++;\n int ans = 0;\n while(hsh.size() != 1) {\n auto it = --hsh.end();\n auto temp = prev(it);\n \n int freq = ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "\n// Idea: use ordered map to maintain the frequency of elements by the magnitude of the elements.\n// let the biggest element be Z and has count cZ, and the second largest element be Y and has count\n// cY, then we'll spend cZ count of operations to make all Z's be Y's, resulting in cY + cZ count of\n// Y...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n map<int, pair<int, int>> map1;\n int last = 0;\n for(int i=0;i<nums.size();i++){\n if(map1.find(nums[i]) == map1.end()){\n map1[nums[...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n // The number of operations on each unique element in initial array = (freq of number) * (no of unique elements strictly less than element)\n int reductionOperations(vector<int>& nums) {\n map<int,int> m;\n for(auto &x:nums)\n m[x]++;\n int ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n map<int,int> m;\n int cnt=1,sum=0;\n m[1]=1;\n sort(nums.begin(),nums.end());\n for(int i=1;i<nums.size();i++)\n {\n if(nums[i]>nums[i-1])\n cnt++;\n m[cnt]++;\n }\n for(auto x:m)\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n set<int> s;\n for(int i=0;i<nums.size();i++)\n s.insert(nums[i]);\n vector<int> v(s.begin(), s.end());\n int ans = 0;\n for(int i=0;i<nums.size();i++){\n int index = lower_...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int all = nums.size();\n unordered_map<int, int> m;\n priority_queue<int> q;\n for (int n : nums) {\n if (++m[n] == 1) q.push(n);\n }\n int todo = 0;\n int ans = 0;\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n // priority queue\n int reductionOperations(vector<int>& nums) {\n unordered_map<int, int> mp;\n for(auto& num: nums) {\n mp[num]++;\n }\n\n priority_queue<int> pq; // maxheap\n for(auto& it: mp) pq.push(it.first);\n\n ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int,int> countMap;\n int maxVal=0;\n for(int num:nums) \n {\n countMap[num]++;\n if(num>maxVal) \n maxVal=num;\n }\n vector<int> uniqueValue...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "\n\nusing namespace std;\n\nclass Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int, int> freq;\n for (int num : nums) {\n freq[num]++;\n }\n \n vector<int> uniqueElements;\n for (const auto& [key, value] : freq) {...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n map<int,int>m;\n int n = nums.size();\n for(int i=0;i<n;i++){\n m[nums[i]]++;\n }\n vector<int>temp;\n for(auto it = m.begin();it!=m.end();it++){\n temp.push_back(it...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n map<int,int>m;\n int n = nums.size();\n for(int i=0;i<n;i++){\n m[nums[i]]++;\n }\n vector<int>temp;\n for(auto it = m.begin();it!=m.end();it++){\n temp.push_back(it...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int reductionOperations(const std::vector<int>& ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int reductionOperations(const std::vector<int>& ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int reductionOperations(const std::vector<int>& ...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n ios::sync_with_stdio(false);\n cout.tie(nullptr);\n cin.tie(nullptr);\n unordered_map<int, int> mp;\n for (int i = 0; i < nums.size(); i++) {\n mp[nums[i]]++;\n }\n vect...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int,int> m;\n int n=nums.size();\n\n for(int i=0;i<n;i++)\n {\n m[nums[i]]++;\n }\n\n vector<pair<int,int>> v;\n\n for(auto a:m)\n v.push_back({a.fi...
2,016
<p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p> <ol> <li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large...
3
{ "code": "class Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(auto num:nums){\n mp[num]++;\n }\n\n priority_queue<pair<int,int>> pq;\n for(auto iter:mp){\n cout<<iter.first<<\" \"<<iter.second<<endl;\n...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nconstexpr size_t MAX_LEN = 100'000;\nstatic std::array<int, MAX_LEN> mp;\n\ninline bool is_odd(int n) {\n return (n % 2) == 1;\n}\ninline bool...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nconstexpr size_t MAX_LEN = 100'000;\nstatic std::array<int, MAX_LEN> mp;\n\ninline bool is_odd(int n) {\n return (n % 2) == 1;\n}\ninline bool...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "class Solution {\npublic:\n int find(vector<int>& nums, int k){\n if(k<0){\n return 0;\n }\n int l=0,r=0,sum=0,ans=0;\n while(r<nums.size()){\n if(nums[r]%2==1){\n sum++;\n }\n while(sum>k&&l<=r){\n if(...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "class Solution {\nprivate:\n int lessthanequalto(vector<int>& nums, int k){\n if(k < 0) return 0;\n int l=0,r=0,cnt=0;\n int odds = 0;\n while(r < nums.size()){\n if(nums[r]%2 == 1) odds++;\n while(odds > k){\n if(nums[l] % 2 == 1) o...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n return (countsubarray(nums,k)-countsubarray(nums,k-1));\n }\n\n int countsubarray(vector<int>& nums, int k){\n int count=0,sum=0;\n int l=0,r=0;\n while(r<nums.size()){\n sum+=(nu...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "class Solution {\npublic:\n int utils(vector<int>&nums, int k){\n if(k<0) return 0;\n int count =0, l=0,r=0;\n int n=nums.size();\n int odds=0;\n while(r<n && l<=r){\n if(nums[r]%2 ==1) odds+=1;\n\n while(odds>k && l<=r){\n if(nums[...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "class Solution {\n int atMostK(vector<int>& nums, int k) {\n int start = 0, end = 0;\n int count = 0;\n int odds = 0;\n\n while (end < nums.size()) {\n if (nums[end] % 2 == 1) {\n odds++;\n }\n\n while (odds > k) {\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
0
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int l = 0, m = 0, r = 0, num_odds = 0, num_sa = 0;\n while (r < nums.size()) {\n if (nums[r] % 2 == 1) {\n ++num_odds;\n }\n ++r;\n\n while (num_odds >...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
1
{ "code": "class Solution {\npublic:\n int subArray(vector<int>& nums, int k){\n if(k < 0) return 0;\n\n int l = 0; int r = 0; int mx = 0; int sum = 0;\n\n while(r < nums.size()){\n if(nums[r] % 2 != 0) sum++;\n\n while(sum > k){\n if(nums[l] % 2 != 0) sum-...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
1
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int l = 0, r = 0;\n int cnt = 0, oddcnt = 0;\n int prefixCount = 0;\n\n while (r < nums.size()) {\n // Expand the window by adding the right element\n if (nums[r] % 2 == 1) oddcn...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\nprivate:\n int func(vector<int>& nums, int goal) {\n if(goal<0)return 0 ;\n int l=0 , r=0 , sum =0 , cnt =0;\n int n =nums.size();\n while(r<n){\n sum+=nums[r]%2;\n while(sum>goal && l<=r){\n sum=sum-(nums[l]%2);\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "#pragma GCC optimize(\"O3\")\n#pragma GCC target(\"avx2, bmi, bmi2, lzcnt, popcnt\")\nstatic const bool __boost = [](){\n cin.tie(nullptr);\n cout.tie(nullptr);\n return ios_base::sync_with_stdio(false);\n}();\nclass Solution {\npublic:\nint solve(vector<int>& nums, int k)\n{\n int cnt=0;\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "auto init = [](){\n ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n // Same as 930. Binary Subarrays With Sum with a tweak\n int numberOfSubarrays(vector<int>& nums, int k) {\n return get(nums,k)-get(nums,k-1);\n }\n\n int ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n //Start at 4:00\n //Nice: k odd numbers, continuous chunk of the array nums\n //k > 0\n\n //Calculating the amount of odd numbers up to and including a particular index\n //Storing that fre...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n \n //Can solve this in O(N)\n int count = 0;\n int curr = 0; //count the # of current odd numbers\n int m[100001] = {0}; //count the # of odd numbers up to index i\n m[0] = 1;\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n }\n int noOfAtmostNice(vector<int>& nums, int k) {\n if (k < 0) return 0;\n int n = nums.size();\n int odds = 0;\n int cnt = 0;\n...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\n vector<bool> convertToBool(vector<int>&nums)\n {\n vector<bool> ans;\n for(auto& it: nums)\n {\n if(it%2==0)\n ans.push_back(false);\n else ans.push_back(true);\n }\n return ans;\n }\n \n int support(v...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n\n int calculate(vector<int>& nums,int k){\n int l=0;\n int r=0;\n int cnt=0;\n unordered_map<int,int> mpp;\n while(r<nums.size()){\n mpp[nums[r]%2]++;\n while(mpp[1]>k){\n mpp[nums[l]%2]--;\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\nprivate:\nint Solve(vector<int>& nums,int target)\n{\n if(target<0) return 0;\n int l=0,r=0,cnt=0,sum=0;\n unordered_map<int,int>mp;\n while(r<nums.size())\n {\n mp[nums[r]%2]++;\n sum+=nums[r]%2;\n while(sum>target)\n {\n sum-=nums[l]...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n int left=0;\n unordered_map<int, int> u;\n int result=0;\n int subarrays =0;\n for(int right=0; right<n; right++){\n if(nums[right]%2 != 0){\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n int left=0;\n unordered_map<int, int> u;\n int result=0;\n int subarrays =0;\n for(int right=0; right<n; right++){\n if(nums[right]%2 != 0){\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& v, int k) {\n int i=0, j=0;\n int count =0;\n int n = v.size();\n int ans = 0;\n deque<int> q;\n\n while (j<n) {\n if (v[j]%2) {\n q.push_back(j);\n }\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int len=0,l=0,o=0;\n queue<int> q;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]%2!=0)\n {\n o++;\n q.push(i);\n }\n i...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n queue<int> q;\n int counter = 0, l = 0, sum = 0;\n for(int i = 0; i < nums.size(); i++){\n...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n\n int num_odds = 0;\n int sum = 0;\n queue<int> last_odds;\n int barrier = -1;\n for (int i = 0; i < nums.size(); i++)\n {\n if (nums[i] % 2 == 1) \n {\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n queue<int> q;\n int ans=0,c=0,j=0;\n for(int i=0;i<nums.size();i++)\n {\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int c=0;\n int ans=0;\n int i=0;\n int j=0;\n int n=nums.size();\n queue<int>q;\n for(i=0;i<n;i++){\n if(nums[i]%2!=0){\n q.push(i);\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n vector<int> arr;\n\n int left=0,right=0,res=0;\n\n while(right<nums.size())\n {\n if(nums[right]%2)\n {\n arr.emplace_back(right);\n }\n\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\r\n bool noofodds(map<char,int>&M,int k){\r\n int cntodds=0;\r\n for(auto it:M){\r\n if(it.first%2!=0){\r\n cntodds+=it.second;\r\n }\r\n }\r\n if(cntodds>k){\r\n return false;\r\n }\r\n return tru...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n vector<int> cum(nums.size()+1,0);\n int out=0,odd=0;\n cum[0]=1;\n for(int i=0;i<nums.size();i++){\n odd+=nums[i]%2;\n cum[odd]++;\n if(odd>=k)out+=cum[odd-k];\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\r\npublic:\r\n int solve(vector<int>&arr,int k){\r\n if(k<0)\r\n return 0;\r\n int i=0,j=0;\r\n int count=0;\r\n int sum=0;\r\n while(j<arr.size()){\r\n sum+=arr[j];\r\n while(sum>k){\r\n sum-=arr[i];\r\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n int ans=0;\n int count=0;\n vector<int> temp(n+1,0);\n temp[0]=1;\n\n for(int num : nums)\n {\n if(num&1)\n {\n count...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int> count(n+1);\n count[0]=1;\n int res=0,odd=0;\n for(int num:nums){\n odd+=num&1;\n if(odd-k>=0)\n res+=count[odd-k];\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int soln(vector<int> & arr, int k){\n if(k<0) return 0;\n int res=0;\n int sum=0;\n int j=0;\n for(int i=0;i<arr.size();i++){\n sum+=arr[i];\n while(sum>k && j<=i){\n sum-=arr[j];\n j++;\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> next(n+1);\n next[n] = n;\n for(int i = n-1; i >= 0; i--) {\n if(nums[i] % 2 == 1) {\n next[i] = i;\n } else {\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> cnt(n + 1, 0);\n cnt[0] = 1;\n int ans = 0, t = 0;\n for (int v : nums) {\n t += v & 1;\n if (t - k >= 0) {\n ans += ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n int count=0;\n int odd=0;\n int i=0,j=0;\n int ind=-1;\n priority_queue<int,vector<int>,greater<int>> q;\n \n while(j<n){\n \n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n /*\n [0,0,0,1,1,1,2,2,2,2,3,3,3,3,3]\n */\n\n int numberOfSubarrays(vector<int>& nums, int k) {\n vector<int> counts({ 1 });\n int pre = 0, res = 0;\n for (int n : nums) {\n pre += n % 2 != 0;\n if (pre == counts.size()) cou...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n int count=0,key=0,prev=0,sum=0;\n vector<int> v;\n for(int i=0;i<n;i++)\n {\n if(nums[i]%2==0)\n {\n nums[i]=0;\n }\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n int count=0,key=0,prev=0,sum=0;\n vector<int> v;\n for(int i=0;i<n;i++)\n {\n if(nums[i]%2==0)\n {\n nums[i]=0;\n }\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int res = 0, count = 0, start = 0, end = 0;\n vector<int> odds = {-1}; \n for(int i = 0; i < nums.size(); i++){\n if(nums[i] & 1) odds.push_back(i);\n }\n odds.push_back(nums.siz...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n vector<int>vec;\n vec.push_back(-1);\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]%2!=0)\n {\n vec.push_back(i);\n }\n }\n vec.pus...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n void print_vi(const vector<int> &vi) {\n cout << \"{ \";\n for (int i : vi) {\n cout << i << \", \";\n }\n cout << '}' << endl;\n }\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n vector<i...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& a, int k) {\n int l = 1, r = 1;\n int oddCount = 1;\n int count = 0;\n\n vector<int> oddIndex;\n oddIndex.push_back(-1);\n\n for(int i = 0; i<a.size(); i++) {\n if(a[i]&1)\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> indices;\n indices.push_back(-1);\n\n int count = 0;\n\n for(int i=0; i<n; i++){\n if(nums[i] & 1 == 1){\n indices.push_back(i);...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int solution(vector<int>& nums, int k){\n int l=0,r=0;\n int ans=0;\n int count=0;\n vector<int> hash;\n while(r<nums.size()){\n if(nums[r]%2==1){\n hash.push_back(r);\n count++;\n }\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int solution(vector<int>& nums, int k){\n int l=0,r=0;\n int ans=0;\n int count=0;\n vector<int> hash;\n while(r<nums.size()){\n if(nums[r]%2==1){\n hash.push_back(r);\n count++;\n }\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\n int countk(vector<int>nums,int k){\n int n=nums.size();\n int count=0,cunt=0;\n int l=0,r=0;\n while(r<n){\n cunt+=(nums[r]%2);\n while(cunt>k){\n cunt-=(nums[l]%2);\n l++;\n }\n ...
1,370
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>. A continuous subarray is called <strong>nice</strong> if there are <code>k</code> odd numbers on it.</p> <p>Return <em>the number of <strong>nice</strong> sub-arrays</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p...
2
{ "code": "class Solution {\npublic:\nint count(vector<int> nums, int goal){\n int sum = 0;\n int l = 0, r = 0;\n int cnt = 0;\n \n if (goal < 0) return 0;\n\n while (r < nums.size()){\n sum += nums[r]%2;\n\n while (sum > goal ){\n sum -= ...