id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue< int, vector<int>, greater<int> > pq_left, pq_right;// {costs[i], i}\n int left_limit = candidates -1, right_limit = costs.size() - candidates ; \n long long min_cost= 0;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue< int, vector<int>, greater<int> > pq_left, pq_right;// {costs[i], i}\n int left_limit = candidates -1, right_limit = costs.size() - candidates ; \n long long min_cost= 0;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int len = costs.size();\n priority_queue<int, vector<int>, greater<int>> q_left, q_right;\n long long total = 0;\n int left = min(candidates, len/2);\n int right = max(len-ca...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n long long cost = 0;\n int n = costs.size() / 2;\n if(candidates * 2 > costs.size()){\n priority_queue<int, vector<int>, greater<int>> p;\n for(int i : costs){\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<int, vector<int>, greater<int>> left, right;\n\n int i=0, j=costs.size()-1;\n while(i < candidates){\n left.push(costs[i]);\n costs[i] = INT_MAX;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<int, vector<int>, greater<int>> left, right;\n\n int i=0, j=costs.size()-1;\n while(i < candidates){\n left.push(costs[i]);\n costs[i] = INT_MAX;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int> &costs, int k, int candidates)\n{\n int n = costs.size();\n long long ans = 0;\n\n if (((2 * candidates) + k - 1) >= n)\n {\n priority_queue<int, vector<int>, greater<int>> pq;\n for (int i = 0; i < n; i++)\n {\...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& c, int k, int ca) {\n vector<int> v(c.size(), 0);\n\n priority_queue<pair<int,int> , vector<pair<int,int>>, greater<pair<int,int>> > p1;\n priority_queue<pair<int,int> , vector<pair<int,int>>, greater<pair<int,int>> > p2;\...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "class Solution {\npublic:\n typedef pair<int, int> ii;\n\n long long totalCost(vector<int>& costs, int k, int candidates) {\n long long result = 0;\n std::priority_queue<ii, std::vector<ii>, std::greater<ii>> pq;\n\n int left_index = candidates - 1;\n int right_index = cos...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
2
{ "code": "#define ll long long\n#define P pair<int, int>\nclass Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n if(n == 1) return costs[0];\n \n priority_queue<P, vector<P>, greater<P>> pq;\n int i = 0, j = n - 1;\...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\n\nprivate:\n\n pair<int, int>p1;\n pair<int, int>p2;\n\npublic:\n\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n long long ans = 0;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n long long res=0;\n int n = costs.size();\n vector<int> hired(n,0);\n \n priority_queue<int,vector<int>,greater<int>> left,right;\n int l=0,r=n-1;\n for(;l<candi...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n\tpriority_queue<int, vector<int>, greater<int>> pqL, pqR;\n\n\tint i = 0, j = costs.size() - 1, temp = candidates;\n\tlong long ans = 0;\n\tdeque<int> dq;\n\tfor (int i = 0; i < costs.size(); i++)\n\t\tdq.push...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n if(2 * candidates >= costs.size()){\n priority_queue<long long> pq;\n for(auto x: costs){\n pq.push(-x);\n }\n\n long long ans = 0;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n\n int n=costs.size();\n\n priority_queue<int,vector<int>,greater<int>>front_queue;\n priority_queue<int,vector<int>,greater<int>>back_queue;\n priority_queue<int,vector<int>,greater...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;\n int n = costs.size();\n vector<bool> isHired(n, false), inQ(n, false);\n for (int i = 0; i < can...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n long long ans = 0;\n auto great = [&](int posa, int posb) -> bool {\n return costs[posa] > costs[posb];\n };\n priority_queue<int, vector<i...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n long long ans = 0;\n auto great = [&](int posa, int posb) -> bool {\n return costs[posa] > costs[posb];\n };\n priority_queue<int, vector<i...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "struct Node {\n int cost;\n int index;\n bool start;\n};\n\n\nstruct Comp {\n bool operator()(Node n1, Node n2) {\n if (n1.cost == n2.cost) {\n return n1.index > n2.index;\n }\n return n1.cost > n2.cost;\n }\n};\n\nclass Solution {\npublic:\n long long tota...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int c) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n int ll=0;\n int lh=c-1;\n int rh=costs.size()-1; ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int c) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n int ll=0;\n int lh=c-1;\n int rh=costs.size()-1; \n int rl= rh-c+1;\n if(lh>=rl){\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int c) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n int ll=0;\n int lh=c-1;\n int rh=costs.size()-1; \n int rl= rh-c+1;\n if(lh>=rl){\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq1, pq2;\n long long ans = 0;\n int n = costs.size();\n candidates = min(candidates, n);\n in...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "typedef long long ll;\ntypedef pair<int,int> pi;\nclass Solution {\npublic:\n ll totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n \n priority_queue<pi,vector<pi>,greater<pi>> leftPQ, rightPQ;\n int leftIndex = 0;\n int rightIndex = n-1;\...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "#define P pair<int,int>\nclass Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidate) {\n priority_queue<P,vector<P>,greater<P>> pq,st;\n long long res = 0;\n int n = costs.size();\n for(int i = 0; i < candidate; i++){\n pq.push({costs[...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n auto pairGreater = [](const pair<int, int> &p1, const pair<int, int> &p2) {\n if (p1.first == p2.first) return p1.second > p2.second;\n return p1.first > p2.first;\n };\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n using pp=pair<int,int>;\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int i,j,n=costs.size();\n priority_queue<int,vector<int>,greater<int>> pqL;\n priority_queue<pp,vector<pp>,greater<pp>> pqR;\n\n for(i=0;i<candidates;i+...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n using pp=pair<int,int>;\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int i,j,n=costs.size();\n priority_queue<int,vector<int>,greater<int>> pqL;\n priority_queue<pp,vector<pp>,greater<pp>> pqR;\n\n for(i=0;i<candidates;i+...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "#include <vector>\n#include <queue>\nusing namespace std;\n\ntypedef pair<long long, long long> pii;\n\nclass Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n ios_base::sync_with_stdio(false);\n priority_queue<pii, vector<pii>, greater<pii>> pq;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "#include <vector>\n#include <queue>\nusing namespace std;\n\ntypedef pair<long long, long long> pii;\n\nclass Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pii, vector<pii>, greater<pii>> pq;\n int n = costs.size();\n int l =...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "typedef pair<long long, long long> pii;\nclass Solution {\n\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n priority_queue<pii,vector<pii>,greater<pii>>pq;\n int n=c...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "#include <format>\n\nclass Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n \n struct Cand {\n int cost;\n int ix;\n int isLeft;\n\n bool operator<(Cand const& other) const {\n return cost > ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n long long cost = 0;\n priority_queue<pair<int, int>, \n vector<pair<int, int>>, greater<pair<int, int>>> minHeapLeft, minHeapRight;\n for (int i = 0; i < candidates; i++) {\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>>q1,q2;\n int n = costs.size();\n int itr1=0, itr2=n-1;\n for(int i=0;i<...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n#define ll long long\n#define p pair<ll,ll>\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<p,vector<p>,greater<p>> start,last;\n int n=costs.size();\n int i=0,j=n-1;\n ll tot=0;\n while(k--){\n wh...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Compare{\n public:\n bool operator()(const pair<int,int> &x, const pair<int,int> &y)\n {\n return x.first > y.first;\n }\n};\n\n\nclass Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n int index_i = 0;\n int...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n struct Tup {\n int cost;\n size_t idx;\n bool left;\n\n bool operator<(const Tup& other) const {\n if (cost == other.cost) {\n return idx > other.idx;\n }\n return cost > other.cost;\n }\n }...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "// long long ans = 0;\n// priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> left;\n// priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> right;\n \n// int n = costs.size();\n \n// for(int i=0;i<n;i++){\n// ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& arr, int k, int c) {\n // create two pqs\n long long ans = 0;\n priority_queue <int, vector<int>, greater<int>> q1, q2;\n int n = arr.size(); int l=c-1; int r = n-c;\n unordered_set<int> q;\n for(int i...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n long long res = 0;\n priority_queue<int,vector<int>,greater<int> > pq1;\n priority_queue<int,vector<int>,greater<int> > pq2;\n map<int,int> m;\n int a = -1;\n for (int...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "struct CompareFn {\n bool operator()(pair<int, int> const& p1, pair<int, int> const& p2) {\n if (p1.first > p2.first) {\n return true;\n } else if (p1.first == p2.first) {\n return p1.second > p2.second;\n }\n return false;\n }\n};\n\nclass Solution {...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n long long ans = 0;\n unordered_map<int, int> mp;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n\n int left = 0, right = costs.size()-1;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n multiset<int> left,right;\n int n = costs.size();\n int lefti = candidates-1;\n int righti = n-candidates;\n long long ans = 0;\n if(righti-lefti<=1){\n sor...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;\n \n unordered_set<int> processedIndi...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;\n \n unordered_set<int> processedIndi...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;\n \n unordered_set<int> processedIndi...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "#include <set>\nstruct Cost{int cost, pos;};\n\nstruct CostCmp\n{\n bool operator()(const Cost& lhs, const Cost& rhs) const\n {\n if( lhs.cost < rhs.cost) {\n return true;\n } \n if ( lhs.cost == rhs.cost ) {\n return( lhs.pos < rhs.pos);\n }\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,\n greater<pair<long long,long long>>> minHeap;\n long long i,maxl,maxr;\n map<long long,long long> mp;\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int cand) {\n long long ans=0;\n if(costs.size()<=2*cand)\n {\n sort(costs.begin(),costs.end());\n for(int i=0;i<k;i++) ans+=costs[i];\n }\n else\n {\n p...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\n\n struct cmp {\n bool operator()(pair<int, int>& a, pair<int, int>& b) {\n return a.second > b.second ||\n a.second == b.second && a.first > b.first;\n }\n };\n\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\n\n struct cmp {\n bool operator()(pair<int, int>& a, pair<int, int>& b) {\n return a.second > b.second ||\n a.second == b.second && a.first > b.first;\n }\n };\n\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n typedef pair<int, int> candidate;\n\n long long totalCost(vector<int>& costs, int k, int candidates) {\n const auto n = costs.size();\n priority_queue<candidate, vector<candidate>, greater<candidate>> lheap;...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int c) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>p1;\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>p2;\n unordered_set<int>s;\n int n= ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\n\n struct cmp {\n bool operator()(pair<int, int>& a, pair<int, int>& b) {\n return a.second > b.second ||\n a.second == b.second && a.first > b.first;\n }\n };\n\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\n\n struct cmp {\n bool operator()(pair<int, int>& a, pair<int, int>& b) {\n return a.second > b.second ||\n a.second == b.second && a.first > b.first;\n }\n };\n\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\n\n struct cmp {\n bool operator()(pair<int, int>& a, pair<int, int>& b) {\n return a.second > b.second ||\n a.second == b.second && a.first > b.first;\n }\n };\n\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> left, right;\n int n = costs.size();\n set<pair<int,int>> m;\n int lc = -1, rc=n;\n for(int i=0;i...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pair<int,int> , vector<pair<int,int>>, greater<pair<int,int>>> pq1, pq2;\n int n = costs.size();\n\n for(int i=0;i<candidates;i++){\n pq1.push({costs[i], i});\n ...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> left, right;\n int n = costs.size();\n set<pair<int,int>> m;\n int lc = -1, rc=n;\n for(int i=0;i...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n priority_queue<\n tuple<int, int, bool>,\n vector<tuple<int, int, bool>>,\n greater<>\n > pq;\n\n int left = 0;\n fo...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n=costs.size();\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n int cnt=0;\n ll ans=0;\n int prev_i=-1,prev_j=n;\n...
2,553
<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p> <p>You are also given two integers <code>k</code> and <code>candidates</code>. We want to hire exactly <code>k</code> workers according to the fol...
3
{ "code": "class Solution {\npublic:\n long long totalCost(vector<int>& costs, int k, int candidates) {\n int n = costs.size();\n set<pair<int, int>> st;\n // long long t = 0;\n // for(auto it: costs) t+= it;\n // cout<<t<<endl;\n int i = 0, j = n - 1;\n while (i < ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n int dp[high+1];\n memset(dp, 0, sizeof(dp));\n dp[0] = 1;\n for(int i=1; i<=high; i++) {\n if(i-zero>=0) {\n dp[i] += dp[i-zero];\n if(dp[i]>=10...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "const int mod=1e9+7;\nclass Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n int dp[high+1];\n memset(dp,0,sizeof(dp));\n dp[0]=1;\n for(int i=1;i<=high;i++){\n if(i>=one) dp[i]=(dp[i] + dp[i-one])%mod;\n if(i>=zero) d...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n const long long int mod=1e9+7;\n int countGoodStrings(int low, int high, int zero, int one) {\n long long int dp[high+1];\n memset(dp,0,sizeof(dp));\n dp[0]=1;\n for(int i=min(one,zero);i<=high;i++){\n if(i>=zero){\n dp...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int minLength, int maxLength, int zeroGroup, int oneGroup) {\n int dp[maxLength + max(oneGroup, zeroGroup)];\n memset(dp, 0, sizeof(dp));\n int mod = 1e9 + 7;\n dp[maxLength] = 1;\n for(int i = maxLength - 1; i >= 0; --i...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n int mini = min(zero, one);\n int maxi = max(zero, one);\n int dp[high+1];\n int ans[high+1];\n int mod = 1000000007;\n\n for(int i = 0 ; i <= high; i++) {\n dp[...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) \n {\n uint64_t res{};\n vector<int> dp(high + 1);\n dp[0] = 1;\n\n for (int len = 1; len <= high; ++len)\n {\n if (len >= zero)\n dp[len] += dp[len - ze...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n vector<int> dp(high+1);\n long long ans=0;\n dp[0]=1;\n int i=min(zero,one);\n int mod=1e9+7;\n for(;i<=high;i++)\n {\n if(i-zero>=0)\n {\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n int ans = 0;\n int MOD = 1e9 + 7;\n vector<int> dp(high + 1, 0);\n dp[0] = 1;\n for (int i = (zero > one ? one : zero); i <= high; i++) {\n if (i >= zero && dp[i - zer...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n // Define the modulo value\n const int MOD = 1e9 + 7;\n\n // dp[i] will store the number of ways to create a string of length 'i'\n std::vector<int> dp(high + 1, 0);\n\n // There...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n vector<int> v(high+1,0);\n v[0] = 1;\n int mod = 1e9+7;\n int sum = 0;\n for(int i = 1; i <= high; i++){\n if(i>=zero){\n v[i] = (v[i]*1LL+v[i-zero])%mo...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
0
{ "code": "\nclass Solution {\npublic:\n // int score(int target, vector<int> dp, int zero, int one){\n // if(target == 0) return 1;\n\n // if(target < 0) return 0;\n\n // if(dp[target] != -1) return dp[target];\n // long long sum;\n\n // sum = score(target-one, dp, zero, one) + ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int dp[100005];\n const int MOD = 1e9 + 7;\n\n int f(int len, int low, int high, int zero, int one) {\n if (len > high) return 0; \n if (dp[len] != -1) return dp[len];\n int ans = 0;\n if (len >= low) {\n ans = 1; \n }\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) \n {\n uint64_t res{};\n deque<int> dp(high + 1);\n dp[0] = 1;\n\n for (int len = 1; len <= high; ++len)\n {\n if (len >= zero)\n dp[len] += dp[len - zer...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n long long dp[100001];\n int z;\n int o;\n const long long MOD = 1000000007;\n \n long long recurse(int i) {\n if (i < 0) return 0;\n if (dp[i] != -1) return dp[i];\n dp[i] = recurse(i-o) + recurse(i-z);\n return dp[i] %= MOD;\n }\...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\n int dp[(int)10e5 + 1];\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n dp[0] = 1;\n const int MOD = (int)1e9 + 7;\n for (int i = 1; i <= high; ++i) {\n if (i - zero >= 0) dp[i] += dp[i-zero];\n if (i - one >= 0) d...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\n int dp[(int)10e5 + 1];\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n dp[0] = 1;\n const int MOD = (int)1e9 + 7;\n for (int i = 1; i <= high; ++i) {\n if (i - zero >= 0) dp[i] += dp[i-zero];\n if (i - one >= 0) d...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\n long long lim = 1e9+7;\n int dp[100001];\n int backtrack(int zero, int one, int len) {\n if (len == 0) return 1;\n if (dp[len] != -1) return dp[len];\n\n long long acc = 0;\n if (len-zero >= 0) acc = (acc + backtrack(zero, one, len-zero)) % lim;\n if (len-one >= 0) acc ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n long ans = 0;\n long MOD = 1e9 + 7;\n vector<long> dp(high + 1, 0);\n dp[0] = 1;\n for (int i = 1; i <= high; i++) {\n if (i >= zero) {\n dp[i] = (dp[i]...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n long ans = 0;\n long MOD = 1e9 + 7;\n vector<long> dp(high + 1, 0);\n dp[0] = 1;\n for (int i = 1; i <= high; i++) {\n if (i >= zero && dp[i - zero]) {\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n long ans = 0;\n long MOD = 1e9 + 7;\n vector<long> dp(high + 1, 0);\n dp[0] = 1;\n for (int i = min(zero, one); i <= high; i++) {\n if (i >= zero && dp[i - zero]) {\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\n static constexpr auto MOD = int(1e9) + 7;\n using DP = vector<long long>;\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n DP dp(high + 1, 0);\n dp.front() = 1;\n long long res = 0;\n for (int end = 1; end <= high; end++)\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n long ans = 0;\n long MOD = 1e9 + 7;\n vector<long> dp(high + 1, 0);\n dp[0] = 1;\n for (int i = (zero > one ? one : zero); i <= high; i++) {\n if (i >= zero && dp[i - ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n long ans = 0;\n long MOD = 1e9 + 7;\n vector<long> dp(high + 1, 0);\n dp[0] = 1;\n for (int i = (zero > one ? one : zero); i <= high; i++) {\n if (i >= zero && dp[i - ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n int ans = 0;\n int MOD = 1e9 + 7;\n vector<long> dp(high + 1, 0);\n dp[0] = 1;\n for (int i = (zero > one ? one : zero); i <= high; i++) {\n if (i >= zero && dp[i - ze...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int L, H, Z, O;\n int mod=1e9+7;\n int dp[100001];\n int solve(int l)\n {\n if(l>H)\n return 0;\n \n if(dp[l]!=-1)\n return dp[l];\n\n bool flag=0;\n\n if(l>=L && l<=H)\n {\n flag=1;\n }\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int L, H, Z, O;\n int mod=1e9+7;\n int dp[100001];\n int solve(int l)\n {\n if(l>H)\n return 0;\n \n if(dp[l]!=-1)\n return dp[l];\n\n bool flag=0;\n\n if(l>=L && l<=H)\n {\n flag=1;\n }\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int mode = 1e9+7;\n int countGoodStrings(int low, int high, int zero, int one) {\n vector<int>dp(high+1,-1);\n int ans = 0;\n for(int len = low;len<=high;len++){\n ans = (ans + solve(one,zero,dp,len))%mode;\n }\n return ans;\n...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n const int m = 1e9 + 7;\n int solve(int zero, int one, int len, vector<int> &dp){\n if(len==0) return 1;\n if(len<0) return 0;\n\n if(dp[len]!=-1) return dp[len];\n int on = solve(zero, one, len - one, ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution\n{\n public:\n\n \n \t//brute force->>using recurssion-TLE \n\n \t// int mod=1e9+7;\n \t\n // int solve(int size,int zero,int one,int n){\n \t// if(size==n){\n \t// return 1;\n \t// }\n \t// if...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n const int m = 1e9 + 7;\n int solve(int zero, int one, int len, vector<int> &dp){\n if(len==0) return 1;\n if(len<0) return 0;\n\n if(dp[len]!=-1) return dp[len];\n int on = solve(zero, one, len - one, dp);\n int ze...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n\n int dp[100100];\n const int mod = 1e9+7;\n\n int rec(int n, int zero, int one){\n //pruning\n if(n<0) return 0;\n\n //basecase\n if(n == 0) return 1;\n\n //cache check\n if(dp[n] != -1) return dp[n];\n\n //compute\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int p = 1000000007;\n int ans;\n int countGoodStrings(int low, int high, int zero, int one) {\n \n int ans = 0;\n vector<int> f;\n f.push_back(1);\n for(int i=1;i<=high; ++i) {\n int temp = 0;\n if (i-zero >= 0) t...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\nint mod=1e9+7;\nint solve(int len,int zero,int one,vector<int>&dp){\n if(len<0){\n return 0;\n }\n if(len==0){\n return 1;\n }\n if(dp[len]!=-1){\n return dp[len];\n }\n int first=(solve(len-one,zero,one,dp))%mod;\n int sec=(solve(len-...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\nint mod=1e9+7;\nvector<int>dp;\n/*int rec(int i,int high,int zero, int one){\n if(i>high)return 0;\n if((i>low&&i<=high))dp[i]++;\n}*/\n int countGoodStrings(int low, int high, int zero, int one) {\n for(int i=0;i<=high;i++)dp.push_back(0);\n dp[0]=1;\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int dp[100001];\n int L;\n int H;\n int Z;\n int O;\n int MOD = 1e9 + 7;\n int solve(int length){\n if(length > H){\n return 0;\n }\n\n if(dp[length] != -1){\n return dp[length];\n }\n\n int current = ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n const int mod = 1e9+7;\n int dp[100005];\n int fn(int low, int high, int zero, int one, int currSize) {\n\n if (currSize > high)\n return 0;\n \n if (dp[currSize] != -1) return dp[currSize];\n \n int add_zero = 0;\n i...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int f(int idx,int zero,int one,vector<int>& dp){\n if(idx == 0) return 1;\n // if(idx<0) return 0;\n if(dp[idx] != -1) return dp[idx];\n int cnt1 = 0,cnt0 = 0;\n if(idx>=zero) cnt0 = f(idx-zero,zero,one,dp);\n if(idx>=one) cnt1 = f(id...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int l, h, z, o, mod = 1e9 + 7;\n bool valid(int n) {return n >= l && n <= h;}\n int countWays(int len, vector<int>&dp) {\n if (len == 0) return 1;\n if (len < 0) return 0;\n if (dp[len] != -1) return dp[len];\n dp[len] = (countWays(len-z, dp)...