id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
0
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n=nums.size();\n long long sum=nums[0];\n k--;\n multiset<int> l,r;\n for(int i=1;i<=min(n,dist+1);i++){\n sum+=nums[i];\n l.insert(nums[i]);\n } ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
0
{ "code": "#define ll long long int\nclass Solution {\n multiset<int> l, r;\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n long long curr = nums[0];\n k--;\n for (int i = 1; i <= dist + 1; i++)\n {\n curr += nums[i];\n...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
0
{ "code": "#define ll long long int\nclass Solution {\nprivate:\nmultiset<int> l, r;\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n ll n = nums.size();\n // Make the first Window for which the elementsthere exists the nums[0] (ofcourse) and the lowest k-1 elemnts of the wind...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
0
{ "code": "#define ll long long int\nclass Solution {\nprivate:\nmultiset<int> l, r;\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n ll n = nums.size();\n k--;\n ll curr = nums[0];\n for(int i=1; i<=dist+1; i++){\n curr += nums[i];\n l.inse...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n long window_sum = 0;\n std::multiset<int> selected;\n std::multiset<int> candidates;\n auto balance = [&]() -> void\n {\n while (static_cast<int>(selected.size()) < k -...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "#define ll long long int\nclass Solution {\n multiset<ll> l, r;\npublic:\n ll minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n k--;\n ll cur = nums[0];\n for (int i = 1; i <= dist + 1; i++) cur += nums[i], l.insert(nums[i]);\n while (l.size...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "class Solution {\n multiset<long long> l, r;\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n k--;\n long long cur = nums[0];\n for (int i = 1; i <= dist + 1; i++) cur += nums[i], l.insert(nums[i]);\n while (l.size() > ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "//sliding window\nclass Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n multiset<long long> st1, st2;\n long long curr = nums[0]; // we need to include thios always\n k--;\n\n // sum of all the elements from in...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n \n multiset<int>m1,m2;\n long long i,n=nums.size(),cnt=nums[0],ans=0;\n for(i=1;i<=dist+1&&i<n...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "class Solution\n{\n multiset<int> l, r;\n\npublic:\n long long minimumCost(vector<int> &nums, int k, int dist)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n int n = nums.size();\n long long cnt = nums[0];\n k--;\n\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "class Solution\n{\n multiset<int> l, r;\n\npublic:\n long long minimumCost(vector<int> &nums, int k, int dist)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n int n = nums.size();\n long long cnt = nums[0];\n k--;\n\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
1
{ "code": "class Solution\n{\n multiset<int> l, r;\n\npublic:\n long long minimumCost(vector<int> &nums, int k, int dist)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n int n = nums.size();\n long long cnt = nums[0];\n k--;\n\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n // return byPQ(nums, k, dist);\n\n return byMultiset(nums, k, dist);\n }\n\n long long byPQ(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n k--;\n\n long long...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n // vector<ll> temp;\n // for(int i = 1;i <= 1 + dist;i++)\n // {\n // temp.push_back(nums[i]);\n // }\n // sort(temp.rbegin(),temp.rend());\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\npublic:\n typedef long long ll;\n \n ll minimumCost(vector<int>& a, int k, int di) {\n multiset<ll>l,r;\n ll s=0;\n int n=a.size();\n for(int i=1;i<=min(n-1,di+1);i++){\n r.insert(a[i]);\n } \n for(int i=0;i<k-1;i++){\n int x=*(r.begin(...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "//m0\n//more general template with balance().\n\n//dual multiset for top k.\n\n//multiset.count() --> TLE. 'cuz it actually counts.\n\n//O(n log dist)\nstatic auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npubl...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "//m0\n//more general template with balance().\n\n//dual multiset for top k.\n\n//multiset.count() --> TLE. 'cuz it actually counts.\n\n//O(n log dist)\nstatic auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npubl...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "//m0\n//more general template with balance().\n\n//dual multiset for top k.\n\n//multiset.count() --> TLE. 'cuz it actually counts.\n\n//O(n log dist)\nstatic auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npubl...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\n\npublic:\n\n // This function calculates the minimum sum of 'k' elements from each consecutive window of 'dist + 1' elements in the 'nums' vector.\n\n long long minimumCost(vector<int>& nums, int k, int dist) {\n\n // The small_set keeps the smallest 'k-1' elements, and the ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "//m0\n//more general template with balance().\n\n//dual multiset for top k.\n\n//multiset.count() --> TLE. 'cuz it actually counts.\n\n//O(n log dist)\nstatic auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npubl...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "//m0\n//more general template with balance().\n\n//dual multiset for top k.\n\n//multiset.count() --> TLE. 'cuz it actually counts.\n\n//O(n log dist)\nstatic auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npubl...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "#define ll long long\nclass Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n ll n=nums.size();\n map<ll,ll> mpmax,mpmin;\n ll res=nums[0],mn=LLONG_MAX;\n // while(i<=n-k+1){\n\n int i=1,j=i;\n ll sum=0;\n for...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n \n int n=nums.size();\n\n multiset<int>m1;\n multiset<int>m2;\n\n long long ans=nums[0];\n \n k--;\n\n for(int i=1;i<=dist+1;i++){\n m1.inse...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "#define remove(t, tmp) t.erase(t.find(tmp)) // remove_one_instance_of_tmp_from_t\n#define max_val(t) *t.rbegin()\n#define min_val(r) *r.begin()\n#define exists(t, val) t.find(val) != t.end()\n#define update(t, r, sum) { int tmp = max_val(t); r.insert(tmp), remove(t, tmp), sum -= tmp; }\n\nclass Solution {...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "using LL = long long;\nclass Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n /*\n [x x x x x] [i1 x x x x] ... [ik-1 x x x x] \n ik-1 - i1 <=dist\n */\n LL min_cost = LONG_LONG_MAX;\n LL sum = 0;\n int n = nums....
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "using LL = long long;\nclass Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n LL min_cost = LONG_LONG_MAX;\n LL sum = 0;\n int n = nums.size();\n multiset<int> set1;\n multiset<int> set2;\n for(int i=1; i<n; i++){\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\n typedef long long int ll;\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n \n ll ans=0;int n =nums.size();\n \n multiset<ll> s;dist += 1;k-=1;\n for(int i=1;i<1+dist;i++){\n s.insert(nums[i]);\n }\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\npublic:\n\nclass MedianFinder{\n multiset<int> right;\n multiset<int, greater<int>> left;\n long long sum = 0;\n int k;\npublic:\n MedianFinder(int _k){\n k = _k;\n }\n long long getSum() {\n return sum;\n } \n void balance(){\n if(left.size...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n // 1. window of size of dist whose k smallest items have the smallest overall sum\n k = k - 1;\n int n = nums.size();\n set<pair<int, int>> smallest_k, largest;\n long long smalle...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "using LL = long long;\nclass Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n // multiset default low to high\n multiset<int> topk, candidates;\n k--;\n LL sum=0, ret=LLONG_MAX;\n int start = 1;\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n set<pair<int, int>> st1; // {value , index}\n set<pair<int, int>> st2; // {value , index}\n int n = nums.size();\n\n long long ans = 9223372036854775807;\n long long temp ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
2
{ "code": "#define ll long long\nclass Solution {\nprivate:\n multiset<int> m1, m2;\n ll sum; \n \n void add(int num, int n){\n // cout<<\"add \"<<num<<endl;\n if((int)m1.size() >= n && num >= *(m1.rbegin())){\n m2.insert(num);\n }else{\n m1.insert(num);\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "void insrt(long long num, multiset<long long> &sml, multiset<long long> &bg, long long &sum, int k){\n // cout<<num<<endl;\n if(sml.size() < k-1){\n sml.insert(num);\n sum += num;\n }else{\n auto it = sml.end();\n it--;\n if(*it > num){\n sml.insert(nu...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n void rearrange(multiset<long long>&m1,multiset<long long>&m2,long long &sum,int k){\n while(m1.size()!=k-1){\n m1.insert(*m2.begin());\n sum+=*m2.begin();\n m2.erase(m2.find(*m2.begin()));\n }\n if(*m1.rbegin()>*m2.begin()...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(std::vector<int>& nums, int k, int dist) {\n // Initializing variables\n long long int initialExpense = nums[0];\n nums.erase(nums.begin());\n int size = nums.size();\n k--;\n dist++;\n std::multiset<long ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "struct maxHeap {\n multiset <int> st;\n long long sum;\n maxHeap() {\n sum = 0;\n }\n void erase (int num) {\n assert (st.size());\n sum -= num;\n st.erase (st.find(num));\n }\n int top() {\n assert (st.size());\n return *st.rbegin();\n }\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n void add(int v, multiset<int>& s, multiset<int>& t, long long& sum, int k) {\n // If the size of set s is less than k - 1, add the element directly to s\n if (s.size() < k - 1) {\n s.insert(v);\n sum += v;\n return;\n }\n\...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n void add(int v, multiset<int>& s, multiset<int>& t, long long& sum, int k) {\n // If the size of set s is less than k - 1, add the element directly to s\n if (s.size() < k - 1) {\n s.insert(v);\n sum += v;\n return;\n }\n\...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class MinKSum{\n private:\n multiset<int> a,b;\n long long sum;\n int k;\n public:\n MinKSum(int k){\n this->k=k;\n this->sum=0;\n a.clear();\n b.clear();\n }\n long long query(){\n repair();\n if(a....
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "#include<iostream>\n#include<vector>\n#include<set>\n\nusing namespace std;\n\n#define ll long long\n\nclass Solution {\npublic:\n void printSet(multiset<ll> values) {\n cout << \"set: \";\n for (auto it = values.begin(); it != values.end(); ++it) {\n cout << *it << \" \";\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "#define ll long long int \n\nclass fenwick{\n vector<ll>sum;\n public:\n fenwick(ll n){\n sum.resize(n+1,0);\n }\n void add(ll idx,ll e){\n idx++;\n ll n=sum.size()-1;\n for(;idx<=n;idx+=(idx&(-idx))){\n sum[idx]+=e;\n }\n }\n //find sum fr...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "#define ll long long int \n\nclass fenwick{\n vector<ll>sum;\n public:\n fenwick(ll n){\n sum.resize(n+1,0);\n }\n void add(ll idx,ll e){\n idx++;\n ll n=sum.size()-1;\n for(;idx<=n;idx+=(idx&(-idx))){\n sum[idx]+=e;\n }\n }\n //find sum fr...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n long long res = 0;\n\n multiset<int> kSmall, rem(nums.begin() + 1, nums.begin() + dist + 2);\n // for(int i = 1; i <= dist + 1; i++)\n // rem.insert(num...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n=nums.size();\n multiset<int> s0(nums.end()-(dist+1),nums.end()),s1;\n long long sum0=accumulate(nums.end()-(dist+1),nums.end(),0LL);\n while(s0.size()>=k)\n {\n a...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n\n vector<int> N;\n int n;\n\n long long minimumCost(vector<int>& nums, int k, int dist) {\n N = nums;\n // k++;\n n = N.size();\n #define int long long\n multiset<int> S;\n multiset<int> A;\n int sum = 0;\n\n int a...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n multiset<long long> minVals;\n multiset<long long> otherVals;\n long long minValSum = 0;\n vector<long long> ans(n, 1e18);\n // long long returnVal =...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n \n long long minimumCost(vector<int>& nums, int k, int d) {\n \n long long res = INT_MAX;\n int n = nums.size();\n \n \n multiset<int> s1,s2;\n \n long long sum = nums[0];\n \n for(int i = 1 ; i <= d+1...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n typedef long long LL;\n int n = nums.size();\n LL ans = LLONG_MAX, sum = 0;\n set<pair<int, int>> lft, rht;\n for (int i = 1; i < n; ++i) {\n lft.insert({nums[i], i});\...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "typedef long long int ll;\n\n#define pii pair<ll, ll>\n#define F first\n#define S second\n\nclass Solution {\n \npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n = nums.size();\n ll ans = 1e18;\n \n set<pii> minK, rest;\n ll sum = 0;\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n struct bag{\n long long sum ;\n int k ;\n multiset<long long >mt1;\n multiset<long long >mt2;\n bag(int _k){\n sum = 0 ;\n k = _k ;\n }\n\n void insert(int x){\n sum += x;\n mt1.inser...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\n typedef long long ll;\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n int n=nums.size();\n multiset<ll>set1,set2;\n ll sum=0;\n for(int i=1;i<=dist+1;i++){\n set1.insert(nums[i]);\n sum+=nums[i];\n ...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution\n{\npublic:\n\tlong long minimumCost(vector<int> &nums, int k, int dist)\n\t{\n\t\tmultiset<int> s1, s2;\n\n\t\tlong long ans = nums[0];\n\t\tint t = k - 1;\n\n\t\t// Initialize the sets and answer.\n\t\tfor (int i = 1; i <= min((int)nums.size() - 1, 1 + dist); i++)\n\t\t{\n\t\t\tif (s1.size...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "\nclass Solution\n{\npublic:\n\tlong long minimumCost(vector<int> &nums, int k, int dist)\n\t{\n\t\tmultiset<int> s1, s2;\n\t\tlong long ans = nums[0];\n\t\tint t = k - 1;\n\n\n\t\tfor (int i = 1; i <= min((int)nums.size() - 1, 1 + dist); i++)\n\t\t{\n\t\t\tif (s1.size() < t)\n\t\t\t{\n\t\t\t\tans += nums[...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "// class Solution {\n// public:\n// long long minimumCost(vector<int>& nums, int k, int dist) {\n// int n=nums.size();\n// multiset<long long>st1,st2;\n// for(int i=1;i<=dist+1;i++){\n// st1.insert(nums[i]);\n// if(st1.size()>k-1){\n// aut...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n \n #define ll long long\n long long minimumCost(vector<int>& nums, int k, int dist) {\n ll ans = 0;\n k--;\n ll maxx = 1e18;\n multiset<ll>st;\n multiset<ll>rem;\n for(int i = 1; i<=dist+1; i++){\n st.insert(nums[i]);...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "\nclass MyStructure {\nprivate:\n\tmultiset<int> M1, M2;\n\tlong long sum;\n\tint K;\n\npublic:\n\tMyStructure(int K) : K(K), sum(0LL) {};\n\n\tvoid add(int x) {\n\t\tM1.insert(x);\n\t\tsum += x;\n\t\tif((int)M1.size() > K) {\n\t\t\tint y = *(M1.begin());\n\t\t\tM1.erase(M1.find(y));\n\t\t\tsum -= y;\n\t\t...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "\nclass MyStructure {\nprivate:\n\tmultiset<int> M1, M2;\n\tlong long sum;\n\tint K;\n\npublic:\n\tMyStructure(int K) : K(K), sum(0LL) {};\n\n\tvoid add(int x) {\n\t\tM1.insert(x);\n\t\tsum += x;\n\t\tif((int)M1.size() > K) {\n\t\t\tint y = *(M1.begin());\n\t\t\tM1.erase(M1.find(y));\n\t\t\tsum -= y;\n\t\t...
3,260
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>, and two <strong>positive</strong> integers <code>k</code> and <code>dist</code>.</p> <p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(vector<int>& nums, int k, int dist) {\n long long ans = LLONG_MAX ; \n int n = nums.size() ; \n // sum of k least element of dist length subarrays\n multiset<int>least_k ,other ; \n int i = 1, j = 0 ; \n long...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int ans = 0;\n int push = 1;\n for(int i = 0;i<word.size();i++){\n if(i==8|| i==16||i==24) push++;\n ans = ans + push;\n }\n return ans;\n \n }\n};", "memory": "7700" }
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n switch (word.size())\n {\n case 0:\n case 1:\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n case 7:\n case 8: return word.s...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int n = word.size();\n int presses = 0;\n int order = 1;\n\n while(n >0){\n if(n>=8){\n presses += 8*order;\n order++;\n n -= 8;\n }\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int n = word.size();\n int press = 1;\n int completePass = n/8;\n int secPass = n % 8;\n int res = 0;\n while(completePass--){\n res += (8 * press);\n press++;\n }\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> arr(26, 0);\n \n\n for(int i=0;i<word.size();i++){\n int temp = word[i]- 'a';\n arr[temp]++;\n }\n sort(arr.begin(), arr.end());\n int ans=0, cnt=0, mul=1;\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n std::vector<int> mp(26, 0);\n\nfor (auto character : word)\n{\n\tmp[character - 'a']++;\n}\n\nint result = 0;\nsort(begin(mp), end(mp), greater<>());\nfor (int i = 0; i < 26; i++)\n{\n\tint freq = mp[i];\n\tif (freq)\n\t{\n\t\tresult ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> freq(26, 0);\n for(auto c: word) freq[c - 'a']++;\n sort(freq.begin(), freq.end(), greater<int>());\n int ans = 0;\n for(int i = 0; i < 26; i++){\n ans += freq[i]*((i/8) + 1);\n }\n return ans;\n}\n};",...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n \n vector<int> vec(26,0);\n int ans=0;\n for(int i=0;i<word.length();i++)\n {\n vec[word[i]-'a']++;\n }\n sort(vec.begin(),vec.end(),greater<int>());\n for(int i=0;i<26;i++)\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n\nstatic 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\nclass Solution {\npublic:\n // void pr(vector<int>& arr){\n // cout<<\"[\";\n // fo...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> vc(26,0);\n for(char c:word)\n {\n vc[c-'a']+=1;\n }\n sort(vc.begin(),vc.end(),greater<int>());\n vector<int> vp(26,4);\n for(int i=0;i<8;++i)\n {\n v...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n set<char> st;\n for(char c:word){\n st.insert(c);\n }\n return solve(st.size());\n }\n\n int solve(int n){\n if(n<=8)\n return n;\n else if(n<=16){\n int count=0...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n set<char> occur;\n for (char c : word) {\n occur.insert(c);\n }\n int n = occur.size();\n if (n <= 8) return n;\n if (n <= 16) return 2*n-8;\n if (n <= 24) return 3*n-24;\n r...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n set<char> s;\n for(char ch:word){\n s.insert(ch);\n }\n\n int n = s.size();\n int presses = 0;\n int order = 1;\n\n while(n >0){\n if(n>=8){\n presses += 8...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n void findInVec(std::vector<int> &indexes, std::vector<int> &values, std::vector<int>::iterator &itV, int x){\n\n itV = std::find(indexes.begin(), indexes.end(), x);\n //std::cout << \"found \" << (char)x << std::endl;\n if(itV != indexes.end()){\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution\n{\npublic:\n int minimumPushes(string word)\n {\n int n = word.size();\n int count = 0, r = 0;\n set<char> s;\n vector<int> v;\n if (n <= 8)\n {\n return n;\n }\n else\n {\n for (char w : word)\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution\n{\npublic:\n int minimumPushes(string word)\n {\n int n = word.size();\n int count = 0, r = 0;\n set<char> s;\n vector<int> v;\n if (n <= 8)\n {\n return n;\n }\n else\n {\n for (char w : word)\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution\n{\npublic:\n int minimumPushes(string word)\n {\n int n = word.size();\n int count = 0, r = 0;\n set<char> s;\n vector<int> v;\n if (n <= 8)\n {\n return n;\n }\n else\n {\n for (char w : word)\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int result = 0;\n unordered_map<int, int>mp;\n\n int assign_key = 2;\n\n for(char ch:word)\n {\n if(assign_key>9)\n assign_key = 2;\n\n mp[assign_key]++;\n re...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int assign_key = 2;\n int res = 0;\n\n unordered_map<int,int> mpp;\n\n for(char &ch: word){\n if(assign_key>9){\n assign_key = 2;\n }\n mpp[assign_key]++;\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int result=0;\n unordered_map<int ,int>mp;\n int assignkey=2;\n for(char &ch:word)\n {\n if(assignkey>9)\n {\n assignkey=2;\n }\n mp[assignkey]+...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n if(word.size()<=8)\n return word.size();\n unordered_map<char,int>mp;\n for(auto it:word)\n {\n mp[it]++;\n }\n vector<int>v;\n for(auto it:mp)\n {\n v.push...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> f(26,0);\n for(auto&c:word){\n f[c-'a']++;\n }\n ranges::sort(f);\n int ans = 0;\n priority_queue<int,vector<int>, greater<>> pq;\n for(int i=0; i<8; i++){\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n\n unordered_map<char, int>mapping;\n //make count of each char in the given string;\n for(auto ch:word){\n mapping[ch]++;\n }\n\n //push the count of every char;\n vector<int> v;\n for(auto p:mapping...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n unordered_map<char, int> mp;\n int res = 0;\n \n for(char ch : word) {\n if(mp.size() / 8 >= 1) {\n mp[ch] = (mp.size() / 8) + 1;\n }\n else if(mp[ch] == 0) {\n ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n //This map will hold all values and their cost.\n unordered_map<char, int> values;\n \n //This array will hold the frequency of each value\n vector<int> freq_vec(26, 0);\n\n //If the costCount variab...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\nunordered_map<char, int> mp;\nfor(auto i:word)\nmp[i]++;\npriority_queue<int> pq;\nfor(auto i:mp)\npq.push(i.second);\nint answer=0;\nint counter=0;\nfor(int i=0; i<8 and pq.empty()==false; i++){\n answer+=pq.top();\n pq.pop();\n} ...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int n = word.size();\n int ans = 0;\n vector<int> freq(26,0);\n\n for(auto ele : word) {\n freq[ele-'a']++;\n }\n sort(freq.rbegin(),freq.rend());\n int c = 0;\n for(int i=0;...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n unordered_map<char, int> mp;\n\n for(int i = 0; i<word.size(); i++){\n mp[word[i]]++;\n }\n\n priority_queue<pair<int, char>> pq;\n \n for(auto i: mp){\n pq.push({i.second, i.fi...
3,275
<p>You are given a string <code>word</code> containing <strong>distinct</strong> lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped w...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string w) {\n vector<int>v(26,0);\n for(auto a:w){\n ++v[a-'a'];\n }\n sort(v.rbegin(),v.rend());\n int s=0;\n for(int i=0;i<v.size();++i){\n if(v[i]==0)\n return s;\n ...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
0
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n sort(points.begin(), points.end(), [&](vector<int>& a, vector<int>& b) {\n return a[0] < b[0];\n });\n\n int ans = 1...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
0
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n sort(points.begin(), points.end());\n int end = points.front()[0] + w;\n int a...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
0
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n sort(points.begin(),points.end());\n int n=points.size();\n int ans=0;\...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
0
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n sort(points.begin(),points.end());\n int cnt=1,n=points.size();\n int end=points[0][0];\n for(int i=1;i<points.size();i++)\n {\n if(points[i][0]-end<=w) contin...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
0
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) \n {\n std::sort(points.begin() , points.end());\n int x = points[0][0];\n int ans = 0;\n for(int i = 1 ; i < points.size() + 1; i++)\n {\n if(i == points.size(...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
0
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n int n = points.size();\n int count=0;\n int end =-1;\n sort(points.begin(), points.end());\n for(int i=0;i<n;i++){\n int start = points[i][0];\n if(...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
0
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n // Sort points by their x-coordinate\n sort(points.begin(), points.end());\n int n = points.size();\n // Initial placement of the first rectangle\n int rectangles = 1;\n ...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
1
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n sort(points.begin(), points.end());\n int c{points[0][0]+w};\n int retVal{1};\n for(const auto& v: points){\n if(v[0] > c){\n retVal++;\n ...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
1
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& point, int w) {\n int n = point.size();\n sort(point.begin(),point.end());\n int count=0;\n int prev = point[0][0];\n for(int i=1;i<n;i++){\n if(point[i][0]-prev<=w){\n ...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
2
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n sort(points.begin(),points.end(),[](vector<int>&a,vector<int>&b){return a[0]>b[0];});\n\n int ans=0;\n int n=points.size();\n vector<bool> vis(n,false);\n for(int i=0;i<n...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
2
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n // sort(points.begin(),points.end(),[&](vector<int> a,vector<int> b) {\n // return a[0] < b[0];...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
2
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n ios_base :: sync_with_stdio(false);\n cin.tie(nullptr);cout.tie(nullptr);\n int ans = 0;\n int start_x = -2;\n vector<int> dau_x(points.size());\n for (int i=0;i<p...
3,390
<p>You are given a 2D integer array <code>points</code>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. You are also given an integer <code>w</code>. Your task is to <strong>cover</strong> <strong>all</strong> the given points with rectangles.</p> <p>Each rectangle has its lower end at some point <code...
2
{ "code": "class Solution {\npublic:\n int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n ios_base :: sync_with_stdio(false);\n cin.tie(nullptr);cout.tie(nullptr);\n int ans = 0;\n int start_x = -2;\n vector<int> dau_x(points.size());\n for (int i=0;i<p...