id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
0
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int s = garbage.size() ; \n\n int truck_M = 0 ; \n int travelM = 0;\n int lastHouseM = 0; \n\n int truck_P = 0 ; \n int travelP = 0;\n int lastHouseP = 0;\n\n int truck_G = 0 ; \n int travelG = 0;\nin...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
0
{ "code": "class Solution {\npublic:\n int travelDuration(int& truck, vector<int>& travel) {\n int sum = 0;\n for(int i=0; i<=truck; i++) {\n sum += travel[i];\n }\n return sum;\n }\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int m=0...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
0
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int g = 0;\n int m = 0;\n int p = 0;\n int n = garbage.size();\n for(int i=0;i<garbage.size();i++)\n {\n for(int j = 0;j<garbage[i].length();j++)\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
0
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n //ptruck\n int pickp=0;\n int travelp=0;\n int lastHousep=0;\n //mtruck\n int pickm=0;\n int travelm=0;\n int lastHousem=0;\n //gtruck\n int p...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
0
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int g = 0;\n int m = 0;\n int p = 0;\n int n = garbage.size();\n for(int i=0;i<garbage.size();i++)\n {\n for(int j = 0;j<garbage[i].length();j++)\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
0
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n\n int total_time = 0;\n int last_metal = 0, last_paper = 0, last_glass = 0;\n\n // Time spent collecting garbage\n int metal_time = 0, paper_time = 0, glass_time = 0;\n\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
2
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n\n int total_time = 0;\n int last_metal = 0, last_paper = 0, last_glass = 0;\n\n // Time spent collecting garbage\n int metal_time = 0, paper_time = 0, glass_time = 0;\n\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
2
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n\n int total_time = 0;\n int last_metal = 0, last_paper = 0, last_glass = 0;\n\n // Time spent collecting garbage\n int metal_time = 0, paper_time = 0, glass_time = 0;\n\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n\n\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int n=garbage.size();\n int Glasthouse=0,Gpickup=0,Gtime=0;\n int Plasthouse=0,Ppickup=0,Ptime=0;\n int Mlasthouse=0,Mpickup=0,Mtime=0;\n\n for(int i=0;i<n;i++){\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n unordered_map<char, int> m = {{'M', 0}, {'P', 1}, {'G', 2}};\n int last[3] = {-1, -1, -1}; //keep track of the last index in garbage\n int count[3] = {0, 0, 0}; //total garbage to col...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n // farthest house from house 0 that has certain garbage type [M, P, G]\n int farthest[3] = {0,0,0};\n //quantity of garbage [M, P, G]\n int quantity[3] = {0,0,0};\n // d...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int cnt[3] = {0, };\n int max_idx[3] = {0, };\n\n for (int i = 0; i < garbage.size(); i++) {\n for (int j = 0; j < garbage[i].size(); j++) {\n if (garbage[i]...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int n = garbage.size(), m = travel.size();\n int last[26]{};\n int ans = 0;\n for (int i = 0; i < n; ++i) {\n ans += garbage[i].size();\n for (char& c : g...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, \n vector<int>& travel) {\n ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n vector<int> prefixarr(garbage.size(),0);\n for(int i=0;i<travel.size();i++){\n prefixarr[i+1] = prefixarr[i]+...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garb, vector<int>& tra) {\n int Pi=-1,Mi=-1,Gi=-1;\n int n=garb.size(), l=0;\n for(int i=n-1;i>=0;i--){\n if(Pi==-1 && garb[i].find('P')!=string::npos)\n Pi=i;\n if(Gi==-1 && garb[...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int result = 0;\n map<char, int> p_garbage { {'M', 0}, {'P', 0}, {'G', 0} };\n vector<int> travel_presum(travel.size() + 1);\n\n for (int i = 1; i < travel_presum.size(); i++)\...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int n = travel.size();\n vector<int> presum(n+1,0);\n for(int i=1;i<=n;i++){\n presum[i] = presum[i-1]+travel[i-1];\n }\n int m=0,p=0,g=0;\n int posM =...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int lastP = 0;\n int lastG = 0;\n int lastM = 0;\n int cntP = 0;\n int cntG = 0;\n int cntM = 0;\n for(int i=0; i<garbage.size(); i++)\n {\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n\n int cost=0;\n int n=garbage.size();\n vector<int>prefix(n);\n prefix[0]=0;\n for(int i=1;i<=travel.size();++i)\n prefix[i]=prefix[i-1]+travel[i-1];\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n unordered_map<char,int> mp,mp2;\n int n = garbage.size();\n for(int i=0;i<n;i++)\n {\n string s = garbage[i];\n for(int j=0;j<s.length();j++)\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "\n\n\n\nint _ = [](){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n inline static constexpr int const max_len = 100001;\npublic:\n int upper = max_len;\n int g[max_len];\n int m[max_len];\n int p[max_len];\npublic:\n int time_t...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "\n\n\n\nint _ = [](){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n inline static constexpr int const max_len = 100001;\npublic:\n int upper = max_len;\n int g[max_len];\n int m[max_len];\n int p[max_len];\npublic:\n int time_t...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n void calc(int i, string &str, unordered_map<char, pair<int,int>>&m){\n\n int mCount = count(str.begin(),str.end(),'M');\n int pCount = count(str.begin(),str.end(),'P');\n int gCount = count(str.begin(),str.end(),'G');\n\n if(mCount!=0){\n if...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "\n\n\n\nint _ = [](){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n inline static constexpr int const max_len = 100001;\npublic:\n int upper = max_len;\n int g[max_len];\n int m[max_len];\n int p[max_len];\npublic:\n int time_t...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "\n\n\n\nint _ = [](){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n inline static constexpr int const max_len = 100001;\npublic:\n int upper = max_len;\n int g[max_len];\n int m[max_len];\n int p[max_len];\npublic:\n int time_t...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int m=0,g=0,p=0,a=0,b=0,c=0;\n vector<int> v(garbage.size(),0);\n v.push_back(0);\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int m=0,g=0,p=0,a=0,b=0,c=0;\n vector<int> v(garbage.size(),0);\n v.push_back(0);\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int m=0,g=0,p=0,a=0,b=0,c=0;\n vector<int> v(garbage.size(),0);\n v.push_back(0);\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int cm = 0, cp = 0, cg = 0;\n int lm = 0, lg = 0, lp = 0;\n vector<long long> prefix(travel.size() + 1, 0);\n\n for (int i = 1; i <= travel.size(); i++) {\n prefix[i...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n long long totalTimeToPick = 0, sz = garbage.size();\n unordered_map<char, int> lastHouseToVisit;\n vector<long long> travelTime(sz-1);\n for(int indx = 0; indx < sz-1; indx++){...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n \n int m=0,g=0,p=0,a=0,b=0,c=0;\n vector<int> v(garbage.size(),0);\n v.push_back(0);\n for(int i=travel.size();i>=0;i--){\n for(int j=0;j<garbage[i].length();j...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n vector<int> PreFixSum;\n PreFixSum.push_back(0);\n for(int x = 0; x<travel.size(); x++)PreFixSum.push_back(PreFixSum[x] + travel[x]);\n int LastG = 0;\n int LastP = 0;\n...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int g=0; //number of glass garbage;\n int p=0;\n int m=0;\n\n int gpos=0;//glass truck last house visited;\n int ppos=0;\n int mpos=0;\n\n for(int i=0;i<ga...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int n = travel.size() + 1;\n vector<int> glass(n, 0), paper(n, 0), metal(n, 0);\n int x = 0;\n for (auto s : garbage) {\n for (int i = 0; i < s.length(); i++) {\n ...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n const int NR_HOUSES = garbage.size();\n vector<int> metal(NR_HOUSES, 0);\n vector<int> plastic(NR_HOUSES, 0);\n vector<int> glass(NR_HOUSES, 0);\n \n\n for (int i...
2,471
<p>You are given a <strong>0-indexed</strong> array of strings <code>garbage</code> where <code>garbage[i]</code> represents the assortment of garbage at the <code>i<sup>th</sup></code> house. <code>garbage[i]</code> consists only of the characters <code>&#39;M&#39;</code>, <code>&#39;P&#39;</code> and <code>&#39;G&#39...
3
{ "code": "class Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n const int NR_HOUSES = garbage.size();\n vector<int> metal(NR_HOUSES, 0);\n vector<int> plastic(NR_HOUSES, 0);\n vector<int> glass(NR_HOUSES, 0);\n \n\n for (int i...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\nprivate:\n static bool topo(const uint16_t k, const vector<vector<int>> &conds, uint16_t sorted[k]) {\n uint16_t deg[k];\n fill(deg, deg + k, 0);\n const uint8_t qk = (k + 63u) >> 6;\n uint64_t adj[k][qk];\n fill(&**adj, &**adj + k * qk, 0);\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n \n int n = rowConditions.size();\n int m = colConditions.size();\n\n vector<vector<int>> res;\n vector<int> tmpRow(k + 1, 0);\...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n vector<int> indegree(k,0);\n vector<int> row(k);\n for(int i=0;i<rowConditions.size();i++){\n indegree[rowConditions[i][1]-1]+=1;...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\nprivate:\n static bool topo(const uint16_t k, const vector<vector<int>> &conds, uint16_t sorted[k]) {\n uint16_t deg[k];\n fill(deg, deg + k, 0);\n const uint8_t qk = (k + 63u) >> 6;\n uint64_t adj[k][qk];\n fill(&**adj, &**adj + k * qk, 0);\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n int find_ind(vector<int>& arr, int value) {\n for (int i = arr.size() - 1; i >= 0; i--)\n if (arr[i] == value) return i;\n\n return -1;\n }\n\n bool value_in(vector<int>& arr, int value) {\n for (int i = 0; i < arr.size(); i++)\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n vector<vector<int>> res;\n\n vector<int> xs;\n if (!initTopo(k, rowConditions, xs)) return res;\n\n vector<int> ys;\n if (!ini...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& row, vector<vector<int>>& col) {\n int count = 0, n = row.size(), m = col.size();\n vector<bool> rowbool(n, true), colbool(m, true);\n vector<bool> kbool(k+1, true), kbool0(k+1, true), k1bool(k+1...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n std::vector<std::vector<int>> buildMatrix(\n int k, \n const std::vector<std::vector<int>> &rowConditions, \n const std::vector<std::vector<int>> &colConditions\n ) {\n static constexpr size_t K = 400;\n\n static std::vector<int> used;\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "//https://hyper-meta.blogspot.com/\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\nauto _=[]()noexcept{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();\nint adj[401][401],asz[401],rsort[400],csort[400],rsz,csz,row[401],col[401],deg[401];\nint q[401],ql,qr;\nclass Solution {\npublic:\n bool ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n //row\n vector<int> idegree(k+1,0);\n for(int i=0;i<rowConditions.size();i++)\n idegree[rowConditions[i][1]]++;\n queue<in...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<int> toposort(vector<vector<int>>& graph, int n) {\n queue<int> q;\n vector<int> ins(n + 1, 0);\n \n for (auto& edge : graph) {\n ins[edge[1]]++;\n }\n \n for (int i = 1; i <= n; i++) {\n if (ins[i]...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n unordered_map<int,int> rowmp;\n unordered_map<int,int> colmp;\n vector<vector<int>> resultm;\n for(int i = 0; i < k; ++i) {\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class BitSet {\npublic:\n bool set(int x) {\n auto old_val = data[x / 64];\n auto mask = (1ULL << (x % 64));\n data[x / 64] |= mask;\n\n return !(old_val & mask);\n }\n int pop(int hint) {\n for (int i = hint / 64; i < (int)data.size(); i++) {\n if (da...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<int> toposort(vector<vector<int>>& graph, int n) {\n queue<int> q;\n vector<int> ins(n + 1, 0);\n \n for (auto& edge : graph) {\n ins[edge[1]]++;\n }\n \n for (int i = 1; i <= n; i++) {\n if (ins[i]...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<int> order(int k, vector<vector<int>> &conds)\n {\n vector<bool> v(k + 1, false);\n vector<int> ret;\n for (int i = 1; i <= k; i++)\n {\n vector<bool> c(k + 1, false);\n for (auto &cond : conds)\n {\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n map<int, int> rowIncomings;\n for (int i = 1; i <= k; i++) {\n rowIncomings[i] = 0;\n }\n\n for (int i = 0; i < rowConditi...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\n\nstd::vector<int> makePriorityQueues(const vector<vector<int>>& conditions)\n{\n std::map<int, int> inbounds;\n\n for (const auto &condition : conditions)\n {\n auto it = inbounds.find(condition[0]);\n if (it != inbounds.end())\n {\n it->second++;...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n bitset<401> rowAdjs[401];\n int inDegreeRow[401] = {};\n for (vector<int>& rowCondition : rowConditions) {\n if (!rowAdjs[rowCond...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\n struct TState\n {\n TState(int16_t k)\n : Children(k + 1)\n , Deg(k + 1)\n { }\n\n void Reset()\n {\n for (auto& c : Children) {\n c.clear();\n }\n\n fill(Deg.begin(), Deg.end(), 0);\n...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\n struct TState\n {\n TState(int16_t k)\n : Children(k + 1)\n , Deg(k + 1)\n { }\n\n void Reset()\n {\n for (auto& c : Children) {\n c.clear();\n }\n\n fill(Deg.begin(), Deg.end(), 0);\n...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\n struct TState\n {\n TState(int16_t k)\n : Children(k + 1)\n , Deg(k + 1)\n { }\n\n void Reset()\n {\n for (auto& c : Children) {\n c.clear();\n }\n\n fill(Deg.begin(), Deg.end(), 0);\n...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n t = 0;\n adj.resize(k);\n discover.resize(k, -1);\n finish.resize(k, -1);\n\n for_each(begin(rowConditions), end(rowConditions...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "bool df(int i, int& c, const vector<vector<int>>& m, vector<int>& l) {\n if (l[i] == -1)\n return true;\n if (l[i] > -2)\n return false;\n l[i] = -1;\n for (int e : m[i]) {\n if (df(e, c, m, l))\n return true;\n }\n l[i] = c++;\n return false;\n}\n\nclas...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n \n vector<int> topsort(vector<vector<bool>>& graph) {\n int k = graph.size();\n vector<int> indeg(k);\n \n for (int i = 0; i < k; i++) {\n for (int j = 0; j < k; j++) {\n if (graph[i][j]) {\n indeg[j]...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n enum class Used : int8_t { NO = 0, YES = 1, IN_PROGRESS = -1 };\n\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n _order.reserve(k);\n auto rowOrder = solve(k, rowConditions);\n auto ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\n#define subS1(v, i) string(v.begin() + i, v.end())\n#define subS2(v, i, j) string(v.begin() + i, v.begin() + j + 1)\n#define e_(vals, val) (vals.find(val) != vals.end())\n#define g_(val) ((exists(memo, val)) ? dic[val] : 1)\n#define _c(x, y) ((x < n && x >= 0 ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\n#define subS1(v, i) string(v.begin() + i, v.end())\n#define subS2(v, i, j) string(v.begin() + i, v.begin() + j + 1)\n#define e_(vals, val) (vals.find(val) != vals.end())\n#define g_(val) ((exists(memo, val)) ? dic[val] : 1)\n#define _c(x, y) ((x < n && x >= 0 ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "// https://leetcode.com/problems/build-a-matrix-with-conditions/\n\n#include <memory_resource>\n\nstatic const auto s_initialize = [] { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return nullptr; }();\n\nclass Solution {\npublic:\n Solution()\n\t\t: m_polyAlloc( &m_m...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\nprivate:\n vector<vector<int>> adj;\n vector<int> indeg, row, col, rowidx, colidx;\n vector<int> toposort(int n) {\n vector<int> ret;\n queue<int> q;\n for (int i = 0; i < n; ++i)\n if (!indeg[i])\n q.push(i);\n while (!q.empt...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "#include <iostream>\n#include <vector>\n#include <queue>\n#include <cstring> // for memset\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n int rowOrder[k], colOrder[k]; // Use ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "static const int fastIO = [] {\n\tstd::ios_base::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);\n\treturn 0;\n}();\n\nclass Solution {\npublic:\n\tvector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n\t\tvector<vector<int>...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\nprivate:\n class LoopTest{\n private:\n const int k;\n vector<vector<bool>> m;\n bool valid_;\n vector<int> poses; \n vector<int> prior; \n int maxprio; \n public:\n LoopTest(int K):k(K),prior(K+1,-1),poses(K+1,1),maxpr...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n\n void dfs(int node,vector<int> adj[],vector<int>& visited,vector<int>& instack,stack<int>& st,int& flag){\n visited[node]=1;\n instack[node]=1;\n for(auto &nei:adj[node]){\n if(visited[nei]){\n if(instack[nei]){\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n\n bool topoSort(vector<int> graph[], int n, vector<int> &indeg, vector<int> &sorted){\n queue<int> q;\n for(int i=1; i<=n; i++) if(indeg[i] == 0) q.push(i);\n int cnt = 0;\n while(q.size()){\n int curr = q.front(); q.pop();\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n //topological sort using BFS (Kahn's algorithm)\n static vector<int> topo_sort(int k, vector<vector<int>>& conditions){\n vector<int> deg(k+1, 0);\n vector<vector<int>> adj(k+1);\n for(auto& edge: conditions){\n int v=edge[0], w=edge[1];\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n \n vector<int> topoSort(vector<vector<int>>& edges, int n) {\n vector<int> adj[n+1];\n vector<int> indegree(n+1, 0);\n vector<int> order;\n\n for (vector<int>& edge : edges) { \n adj[edge[0]].push_back(edge[1]);\n indegree[...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n static vector<int> topo_sort(int k, vector<vector<int>>& conditions){\n vector<int> deg(k+1, 0);\n vector<vector<int>> adj(k+1);\n for(auto& edge: conditions){\n int v=edge[0], w=edge[1];\n adj[v].push_back(w);\n deg[w]++;...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& adj, int i, vector<int>& visited, vector<int>& order, int& cycle) {\n visited[i] = 1;\n cout<<i<<endl;\n for(int y : adj[i]) {\n cout<<y<<\" \"<<\"print\"<<endl;\n if(visited[y] == 1) {\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\nvector<int> topologicalSort(int k, const vector<vector<int>>& conditions) {\n vector<int> indegree(k + 1, 0);\n vector<vector<int>> adj(k + 1);\n\n // Build the graph and calculate the in-degrees\n for (const auto& condition : conditions) {\n int u = condition[...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n auto topoSort = [&](vector<vector<int>>& conditions) -> vector<int> {\n vector<int> inDegree(k + 1, 0);\n vector<vector<int>> graph(...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\n void solve(int k, vector<vector<int>>& conditions, vector<int>& idx) {\n queue<int> queue;\n vector<int> degree(k + 1);\n vector<vector<int>> E(k + 1);\n for (auto& condition: conditions) {\n int num0 = condition[0];\n int num1 = condi...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n bool topologicalOrder(int k, bool isRow, unordered_map<int, pair<int, int>>& indexMap, vector<vector<int>>& graph) {\n vector<int> indegree(k + 1);\n indegree[0] = 1;\n for (auto& x : graph)\n for (auto& y : x)\n indegree[y]++;\n...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n vector<int>toposort(int V,vector<int>adj[]){\n\t vector<int>indegree(V+1,0),topo;\n\t for(int i=1;i<V+1;i++){\n\t for(auto it:adj[i]){\n\t indegree[it]++;\n\t }\n\t }\n\t queue<int>q;\n\t for(int i=1;i<V+1;i++){\n\t if(indegree[i...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "#define ll long long\n\nclass Solution {\npublic:\nvector<int>toposort(int k ,vector<vector<int>>&edges){\nvector<int>adj[k+1];\nfor(auto &it : edges){\n adj[it[0]].push_back(it[1]);\n}\n\nvector<ll> ind(k + 1, 0);\n queue<ll> q;\n for (auto &it : edges)\n {\n ind[it[1]]++;\n }\n\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\n vector<int> TopoSort(int k, const vector<vector<int>>& edges) {\n unordered_map<int, vector<int>> graph;\n vector<int> deg(k + 1); \n for (const auto& e : edges) {\n graph[e[0]].push_back(e[1]);\n ++deg[e[1]];\n }\n queue<int> q...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n /* bool dfs(int i,vector<vector<int>>&adj,int & c,map<int,int>&h,vector<bool>&visited,map<int,int>&h1){\n visited[i]=1;\n h1[i]=1;\n for(int j:adj[i]){\n if(!visited[j]){\n bool check=dfs(j,adj,c,h,visited,h1);\n if...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n vector<int> topoSort(vector<vector<int>>& grid,int k,bool& cycle){\n vector<int>ans;\n vector<int>indegree(k+1);\n unordered_map<int,vector<int>>adj;\n queue<int>q;\n for(auto& edge:grid){\n int u=edge[0];\n int v=edge[...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n vector<int> topologicalSort(int k, vector<vector<int>>& conditions) {\n vector<int> inDegree(k + 1, 0); // To store in-degree for each node\n unordered_map<int, vector<int>> adjList; // Adjacency list for the graph\n \n // Build the adjacency list and in-degree...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n\n vector<int> topoSort(vector<vector<int>>& edges, int n) {\n unordered_map<int, vector<int>> adj;\n stack<int> st;\n vector<int> order;\n vector<int> visited(n + 1, 0);\n bool hasCycle = false;\n\n for (vector<int>& edge : edges) {...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n\n vector<int> topoSort(vector<vector<int>>& edges, int n) {\n unordered_map<int, vector<int>> adj;\n stack<int> st;\n vector<int> order;\n vector<int> visited(n + 1, 0);\n bool hasCycle = false;\n\n for (vector<int>& edge : edges) {...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\nvoid dfs(int node, vector<int>& visited, unordered_map<int, vector<int>>& mp, stack<int>& st, bool& cycle) {\n visited[node] = 1; // Mark node as being visited\n for (auto it : mp[node]) {\n if (visited[it] == 0) {\n dfs(it, visited, mp, s...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\n vector<int> toposort(vector<vector<int>> &adj){\n int n=adj.size();\n vector<int> indegree(n,0);\n for(int i=0;i<n;++i){\n for(auto &c:adj[i]) indegree[c]++;\n }\n queue<int> q;\n for(int i=0;i<n;++i){\n if(indegree[i]==0...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n bool impossible = false;\n\n vector<int> dfs(int i, vector<vector<bool>>& tree, vector<int>& was) {\n vector<int> res;\n\n stack<pair<int, int>> st;\n st.push({i, 0});\n while(!st.empty() && !impossible) {\n pair<int, int> cur = st.to...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\nprivate:\n bool dfs(int u, vector<int>& order, vector<bool>& vis, vector<bool>& pathVis, unordered_map<int, vector<int>>& adj){\n vis[u] = true;\n pathVis[u] = true;\n\n for(const int& v : adj[u]){\n if(!vis[v]){\n if(dfs(v, order, vis, pa...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\nprivate:\n bool dfs(int u, vector<int>& order, vector<bool>& vis, vector<bool>& pathVis, unordered_map<int, vector<int>>& adj){\n vis[u] = true;\n pathVis[u] = true;\n\n for(const int& v : adj[u]){\n if(!vis[v]){\n if(dfs(v, order, vis, pa...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n int nope = 0;\n void ts(vector<int> &ans, vector<vector<int>> &edges){\n vector<int> adj[402];\n vector<int> in(402,0);\n vector<int> vis(402,0);\n unordered_map<int,int> mp;\n queue<int> q;\n for(int i = 0; i<edges.size(); i++){\n...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\nprivate:\n vector<int> buildTopo(int n, vector<vector<int>>& cond){\n vector<int> graph[n];\n vector<int> indegree(n, 0);\n for(vector<int>& arr : cond){\n graph[arr[0] - 1].push_back(arr[1] - 1);\n indegree[arr[1] - 1]++;\n }\n\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n static vector<int> tsort(vector<vector<int>>& conditions, const int& k) {\n vector<int> g[k], in(k,0);\n for (auto& a : conditions) {\n g[a[0] - 1].emplace_back(a[1] - 1);\n in[a[1] - 1]++;\n }\n queue<int> q;\n for(int...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n\n vector<int> topoSort(vector<vector<int>>& conditions,int k){\n queue<int> q;\n vector<int> topoSort;\n vector<int> indegree(k+1,0);\n vector<int> adj[k+1];\n int count=0;\n for(auto& edge:conditions){\n int u = edge[0];\n...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n unordered_map<int, vector<int>> graph;\n for (const auto& edge : rowConditions) {\n graph[edge[0]].push_back(edge[1]);\n }\n\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
2
{ "code": "class Solution {\npublic:\n bool topological_sort(vector<int>& val , vector<int>& degree , vector<vector<int>>& adj){\n queue<int> q ;\n int count{0} ;\n for(int i = 0 ; i < degree.size() ; i++) if( degree[i] == 0 ) q.push(i) ;\n while( !q.empty() ){\n val[q.front(...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
2
{ "code": "class Solution {\npublic:\n bool topological_sort(vector<int>& val , vector<int>& degree , vector<vector<int>>& adj){\n queue<int> q ;\n int count{0} ;\n for(int i = 0 ; i < degree.size() ; i++) if( degree[i] == 0 ) q.push(i) ;\n while( !q.empty() ){\n val[q.front(...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
2
{ "code": "class Solution {\npublic:\n vector<int>topoSort(vector<int>adj1[] , int k)\n {\n vector<int>indegree(k + 1 ,0) ;\n for(int i =1 ; i <= k ; i ++)\n {\n for(auto it : adj1[i])\n {\n indegree[it] ++;\n }\n }\n ...
2,472
<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given:</p> <ul> <li>a 2D integer array <code>rowConditions</code> of size <code>n</code> where <code>rowConditions[i] = [above<sub>i</sub>, below<sub>i</sub>]</code>, and</li> <li>a 2D integer array <code>colConditions</code> of size <...
2
{ "code": "class Solution {\npublic:\n bool dfs(stack<int>& st, vector<vector<int>>& adj, int u, vector<int>& vis)\n {\n if (vis[u] == 2) return false;\n if (vis[u] == 1) return true; // visiting node again encountered\n\n vis[u] = 1;\n\n for(int& v:adj[u])\n {\n if...