id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n vector<int> smallestSufficientTeam(vector<string>& req_skills,\n vector<vector<string>>& people) {\n unordered_map<string, int> mp;\n int all = 0;\n for (int i = 0; i < req_skills.size(); ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& skills, vector<vector<string>>& people) {\n int k = 0, i, j, n = people.size(), x;\n map<string,int>mp;\n for(i=0;i<skills.size();i++) {\n k = k*2 + 1;\n mp[skills[i]] = i;\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\npublic:\n \n int m, n;\n int target_mask;\n vector<int> result;\n vector<vector<int>> t;\n \n void solve(vector<int> &people , int idx , vector<int> &temp, int mask ) {\n \n if(idx == people.size()) {\n if(mask == target_mask) {\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "// Approach-2 (Using vector<vector<int>> instead of unordered_map to memoize)\n\nclass Solution {\npublic:\n int m, n;\n int target_mask;\n vector<int> result;\n vector<vector<int>> t;\n\n void solve(vector<int>& people, int idx, vector<int>& temp, int mask) {\n\n if (idx == people.si...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution \n{\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) \n {\n int n = req_skills.size();\n std::unordered_map<std::string, int> skillToIndex;\n\n for (int i = 0; i < n; ++i)\n skillToIndex[req_skills...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution \n{\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) \n {\n int n = req_skills.size();\n std::unordered_map<std::string, int> skillToIndex;\n\n for (int i = 0; i < n; ++i)\n skillToIndex[req_skills...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n int i,n= req_skills.size();\n unordered_map<int,vector<int>>dp ;\n dp.reserve(1<<n);\n dp[0]= {};\n unordered_map<string,int>skillindex;\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n int n = req_skills.size();\n unordered_map<int, vector<int>> dp;\n unordered_map<string, int> skill_map;\n\n dp.reserve(1<<n);\n dp[0] = {};\n...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\n void recur(int skillsMask,vector<int> &people_skills,int n,int m, vector<int> &result, vector<int> &temp,vector<vector<int>> &dp){\n if(skillsMask==((1<<m)-1)) {\n if(result.size()==0 || temp.size()<result.size())\n result=temp;\n return;\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\n unordered_map<string,int>skillmap;\n int minsz = 61;\n int dp[61][1<<16];\n bool choice[61][1<<16];\n int solve( vector<vector<string>>& people,int i,int currbit,int reqbit){\n int n = people.size();\n if(i>=n){\n if(currbit == reqbit){\n return ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n\n int n = req_skills.size();\n int m = people.size();\n \n unordered_map<string, int> skill_index;\n for (int i = 0; i < n; ++i) {\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\npublic:\n int m , n;\n int target_mask;\n vector<int> result ;\n\n unordered_map<string , int> dp;\n\n void solve(vector<int> &people_skill , int idx ,vector<int>&temp , int mask ){\n\n if(idx==people_skill.size()){\n if(mask==target_mask){\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\npublic:\n//req_skill-> rs and people ->p\n int n,m;\n int tm;\n vector<int>result;\n\n unordered_map<string,int>dp;\n\n void solve(vector<int>&ps , int idx,vector<int>&temp,int mask){\n if(idx == ps.size()){\n if(mask == tm){\n if(result.siz...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
2
{ "code": "class Solution {\npublic:\n int n , m , target_mask ; \n unordered_map<string,int>dp ; \n vector<int>result ; \n void solve(vector<int>&people_skill , int idx , vector<int>& temp , int mask){\n if(idx >=people_skill.size()){\n if(mask==target_mask){\n if(result....
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& a, vector<vector<string>>& b) {\n map<string, int> mp;\n for (int i = 0; i < a.size(); ++i) {\n mp[a[i]] = i;\n }\n int m = a.size(), n = b.size();\n vector<int> mask(n, 0);\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n\n int f(vector<vector<int>> &dp, vector<vector<int>> &choice, vector<int> &skillSet,int index, int mask, int n,int m){\n // Base Case\n if(mask==(1<<m)-1) return 0;\n if(index==n) return 1e5;\n\n if(dp[index][mask]!=-1) return dp[index][mask];\n\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& r, vector<vector<string>>& p) {\n int n = r.size();\n int m = p.size();\n map<string,int> mp;\n for(int i = 0; i<n; i++){\n mp[r[i]] = i;\n }\n vector<pair<long long,long l...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& r, vector<vector<string>>& p) {\n int n = r.size();\n int m = p.size();\n map<string,int> mp;\n for(int i = 0; i<n; i++){\n mp[r[i]] = i;\n }\n vector<pair<long long,long l...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "\nclass Solution {\npublic:\n void ans(int i, vector<int>& pskills, vector<int>& temp, vector<int>& re,\n int currentm, int req, unordered_map<string, int>& dp) {\n if (i >= pskills.size()) {\n if (currentm == pow(2, req) - 1) {\n if (re.size() == 0 || re.siz...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n\n vector<int> smallestSufficientTeam(vector<string>& s, vector<vector<string>>& t) {\n \n int n=s.size();\n map<string,int>mp;\n for(int i=0;i<n;i++){\n mp[s[i]]=i;\n }\n int m=t.size();\n vector<int>g[m];\n\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "using ll=long long;\nclass Solution {\n vector<vector<ll>>dp;\n ll memo(int ind,vector<int>&peep,int skill_mask,int skill_cnt){\n if(skill_mask==(1<<skill_cnt)-1)return 0;\n if(ind>=peep.size())return (1LL<<peep.size())-1LL;\n \n if(dp[skill_mask][ind]!=-1)return dp[skill_...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "using ll=long long;\nclass Solution {\n vector<vector<ll>>dp;\n ll memo(int ind,vector<int>&peep,int skill_mask,int skill_cnt){\n if(skill_mask==(1<<skill_cnt)-1)return 0;\n if(ind>=peep.size())return (1LL<<peep.size())-1LL;\n \n if(dp[skill_mask][ind]!=-1)return dp[skill_...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "using ll=long long;\nclass Solution {\n vector<vector<ll>>dp;\n ll memo(int ind,vector<int>&peep,int skill_mask,int skill_cnt){\n if(skill_mask==(1<<skill_cnt)-1)return 0;\n if(ind>=peep.size())return (1LL<<peep.size())-1LL;\n \n if(dp[skill_mask][ind]!=-1)return dp[skill_...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "using ll=long long;\nclass Solution {\n vector<vector<ll>>dp;\n ll memo(int ind,vector<int>&peep,int skill_mask,int skill_cnt){\n if(skill_mask==(1<<skill_cnt)-1)return 0;\n if(ind>=peep.size())return (1LL<<peep.size())-1LL;\n \n if(dp[skill_mask][ind]!=-1)return dp[skill_...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "#define ll long long \n#define REP(i,a,n)for(int i=a;i<n;i++)\n#define f first\n#define sec second \nclass Solution {\npublic:\n ll func(ll i,ll mask,vector<vector<ll>>&dp,ll n,vector<vector<string>>&p,unordered_map<string,ll>&m)\n {\n if(mask==0)return 0;\n if(i==n)return 1e18;\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n int solve(int index,int mask,vector<int>&skill,int &n, vector<vector<int>>&dp,vector<vector<int>>&did){\n if(mask==(1<<n)-1){\n return 0;\n }\n if(index==skill.size()){\n return 200;\n }\n if(dp[mask][index]!=-1)return ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n int n = (req_skills).size();\n int m = (int)people.size();\n map<string, int> mapping;\n for(int i = 0 ; i < n; i++){\n mapping[req_skills...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\nunordered_map<string,int> dp;\nvoid f(int i , int mask, int req, vector<int>&temp, vector<int>&res,vector<int> &people_skill)\n{\n if(i>=people_skill.size())\n {\n if(mask == req)\n {\n if(res.size()==0 || res.size()>temp.size())\n {\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n int solve(vector<int>&pple,int limit,int curr,int ind){\n if(ind==pple.size()){\n if(curr==limit)return 0;\n return INT_MAX;\n }\n \n \n int taken=INT_MAX;\n int ret=solve(pple,limit,curr|pple[ind],ind+1);\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& v, vector<vector<string>>& b) {\n int n=v.size();\n map<int,vector<int>> mask;\n mask[0]={};\n map<string,int>mip;\n for(int i=0; i<n; i++) mip[v[i]]=i;\n for(int i=0; i<b.size(); i++...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\nvector<int>result;\nunordered_map<string,int>dp;\nvoid solve(vector<int>&people_skill,int destination,int idx,vector<int>&temp,int mask){\n if(idx==people_skill.size()){\n if(mask==destination){\n if(result.size()==0||result.size()>=temp.size()){\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> res;\n int m , n , target_mask;\n unordered_map<string,int> dp;\n void solve(vector<int> &people_skill , int ind , vector<int>&temp , int mask)\n {\n if(ind >= people_skill.size())\n {\n if(mask == target_mask)\n {\n...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n\n int n,m;\n int target_mask;\n vector<int> result;\n\n unordered_map<string, int> dp;\n\n void solve(vector<int>& people_skill, int index, vector<int>& temp, int mask) {\n\n if(index == people_skill.size()) {\n if(mask == target_mask) {\...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n vector<int> find(unordered_map<string, int>& skills, vector<vector<string>>& people, int mask){\n // cout << mask << '\\n';\n if (mask == 0)\n return {};\n if (dp[mask].size() != 0)\n return dp[mask];\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n unordered_map<string, ll> dp;\n vector<int> mask;\n ll f(int k, int idx, int currmask) {\n if (currmask == k)\n return 0;\n\n if(idx == mask.size())\n return INT_MAX;\n\n string key = to_string(idx)+\" \"+to_...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "#define ll long long int\nclass Solution {\npublic:\n unordered_map<string, ll> dp;\n ll f(ll i,vector<ll> &hash,ll mask,ll n){\n if(mask==(1<<n)-1) return 0;\n if(i>=hash.size()){\n return INT_MAX;\n }\n string key=to_string(i)+\" \"+to_string(mask);\n i...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "#define ll long long int\nclass Solution {\npublic:\n unordered_map<string, ll> dp;\n ll f(ll i,vector<ll> &hash,ll mask,ll n){\n if(mask==(1<<n)-1) return 0;\n if(i>=hash.size()){\n return INT_MAX;\n }\n string key=to_string(i)+\" \"+to_string(mask);\n i...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\nint n,m;\nvector<int> anss;\nbool chc[1<<16][65];\nint func(int i, int val, int need, vector<int> &per, map<string,int> &dp){\n \n if(val==need) return 0;\n if(i>=m) return 1e8;\n\nif(dp[to_string(i)+\" \"+ to_string(val)]) return dp[to_string(i)+\" \"+ to_string(val)];...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n int n = req_skills.size(); // Number of required skills\n int m = people.size(); // Number of people\n\n // Map each skill to an index\n unordere...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& r, vector<vector<string>>& p) {\n ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n int n = r.size();\n unordered_map<int, vector<int>> ans;\n ans[0] = {};\n\n unordered_map<s...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\n unordered_map<string,int>skillmap;\n int minsz = 61;\n int dp[61][1<<17];\n vector<int>ans;\n void solve( vector<vector<string>>& people,int i,int currbit,int reqbit,vector<int>&curr){\n int n = people.size();\n if(i>=n){\n if(currbit == reqbit){\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\n unordered_map<string,int>skillmap;\n int minsz = 61;\n int dp[61][1<<17];\n vector<int>ans;\n void solve( vector<vector<string>>& people,int i,int currbit,int reqbit,vector<int>&curr){\n int n = people.size();\n if(i>=n){\n if(currbit == reqbit){\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n unordered_map<string,int> map;\n int x=0;\n for(auto &i:people){\n for(auto &j:i){\n if(map.find(j)==map.end()){\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n pair<int, vector<int>> dfs(int i, vector<vector<string>> &people, vector<string> &req_skills, int mask, map<pair<int, int>, pair<int, vector<int>>> &dp){\n if(mask==(1<<req_skills.size())-1) return {0, {}};\n if(i==people.size()) return {INT_MAX, {}};\n i...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\n vector<vector<int>> dp;\n int n;\n \n vector<int> minPeople(int mask, \n vector<bool>& peopleVis,\n map<int, vector<int>>& skillToPeopleMap, \n map<int, vector<int>>& peopleToSkillMap) {\n // co...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n\n int findcomone(int a, int b){\n int c = a&b;\n int co = 0;\n while(c!=0){\n co+=(c&1);\n c>>=1;\n }\n return co;\n }\n\n pair<int,vector<int>> helper(int n, int skill, vector<int>& peopmap, vector<unordered_map<...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n\n int findcomone(int a, int b){\n int c = a&b;\n int co = 0;\n while(c!=0){\n co+=(c&1);\n c>>=1;\n }\n return co;\n }\n\n pair<int,vector<int>> helper(int n, int skill, vector<int>& peopmap, vector<unordered_map<...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <bitset>\n#include <utility>\n\nusing namespace std;\n\nclass Solution {\npublic:\n map<pair<int, int>, pair<bool, vector<int>>> dp;\n\n \n int getSkillBitset(const vector<string>& req_skills, const vector<string>& current_ski...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n unordered_map<string, int> skill_to_idx;\n int skills_num = 0;\n for(string &skill: req_skills) {\n skill_to_idx[skill] = skills_num++;\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n unordered_map<string, int> skill_to_idx;\n int skills_num = 0;\n for(string &skill: req_skills) {\n skill_to_idx[skill] = skills_num++;\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "#define ll long long\n\nbool dp[61][66000][61];\nll xf;\n\nvector<int> res;\nll mn;\n\nvoid find(int pos, int mask, int cnt, vector<int> &arr, vector< vector<ll> > &st, int n)\n{\n\n if(pos == st.size())\n {\n if(mask == xf)\n {\n if(arr.size() < mn)\n {\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> ans; // To store the result team\n \n // Modified function to use bitmask\n pair<int, vector<int>> f(int index, int mask, vector<int>& pl, map<pair<int, int>, pair<int, vector<int>>>& dp) {\n if (mask == 0) return {0, {}}; // All skills covered\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n int minChosen;\n long min;\n int end;\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n minChosen = INT_MAX;\n min = 0;\n end = (1 << req_skills.size()) - 1;\n std::cout << \"End: \" << en...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n int end;\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n end = (1 << req_skills.size()) - 1;\n unordered_map<string, int> m;\n for(int i = 0; i < req_skills.size(); i++) {\n m[req_skills[i...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n map<pair<int,int>,pair<bool,vector<int>>> x;\n unordered_map<string,int> m;\n int n;\n pair<bool,vector<int>> dp(int i,int state,vector<vector<string>>& people){\n if(state==(1<<n)-1) return {true,{}};\n if(i==people.size()){\n return {fal...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\nmap<pair<int,int>,pair<long long,vector<int>>>dp;\n\npair<long long,vector<int>> func(vector<string> &req_skills,vector<vector<string>> &people,int ind,int mask){\n if(ind==people.size()){\n if (mask==((1<<req_skills.size())-1))return {0,{}};\n else return {INT_M...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& arr, vector<vector<string>>& people) {\n int n = arr.size();\n unordered_map<string, int> mp;\n for(int i = 0; i<n; i++) mp[arr[i]] = i;\n vector<int> bitArray;\n for(auto it: people){\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
3
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& arr, vector<vector<string>>& people) {\n int n = arr.size();\n unordered_map<string, int> mp;\n for(int i = 0; i<n; i++) mp[arr[i]] = i;\n vector<int> bitArray;\n for(auto it: people){\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n\n vector<int> blue_dist(n, INT_MAX-1);\n vector<int> red_dist(n, INT_MAX-1);\n blue_dist[0] = red_dist[0] = 0;\n\n int count = n-1;\n while ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n\n vector<int> blue_dist(n, INT_MAX-1);\n vector<int> red_dist(n, INT_MAX-1);\n blue_dist[0] = red_dist[0] = 0;\n\n int count = n-1;\n while ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<int> distr(n,INT_MAX),distb(n,INT_MAX);\n int nn = redEdges.size();\n int mm = blueEdges.size();\n \n vector<int> r[n],b[n],ans(...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n //two graphs of red and blue edges, bfs\n vector<int>gr[n], gb[n];\n for(auto& e:redEdges) gr[e[0]].push_back(e[1]);\n for(auto& e:blueEd...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n \n // Adjacency list for red and blue edges\n vector<pair<int,int>> adj[n];\n \n // Build the graph\n for(auto &it : redEdg...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n \n vector<vector<pair<int, int>>> adj(n);\n for(int i=0; i<redEdges.size(); i++){\n adj[redEdges[i][0]].push_back({redEdges[i][1], 0}...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<vector<int>>> g(2, vector<vector<int>>(n));\n for (auto& e : redEdges) {\n g[0][e[0]].push_back(e[1]);\n }\n for...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
0
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<int> red[n];\n vector<int> blue[n];\n vector<int> ans(n);\n for(int i = 0; i < n; i++){\n ans[i] = -1;\n }\n\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
1
{ "code": "// red is 0\n// blue is 1\nclass Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges,\n vector<vector<int>>& blueEdges) {\n vector<vector<pair<int, bool>>> adj(n); \n\n // Fill the adjacency list\n f...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
1
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<int, vector<int>> redGraph, blueGraph;\n for(int i=0;i<redEdges.size();i++)\n redGraph[redEdges[i][0]].push_back(redEdges[i][1...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
2
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n // Using unordered_map as a replacement for Python's defaultdict\n unordered_map<int, vector<int>> red, blue;\n \n // Fill the red and bl...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "\nclass Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) \n {\n multiset<int> temp;\n vector<multiset<int>> redChilds(n, temp), blueChilds(n, temp);\n for(auto j : redEdges)\n {\n re...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n queue<vector<int>>q;\n vector<vector<int>> seen(n, vector<int> (3, 0));\n map<int, vector<int>> red;\n map<int, vector<int>> blue;\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<int, vector<int>> red_table, blue_table, used_red, used_blue;\n for(auto &edge : redEdges){\n red_table[edge[0]].push_back(edg...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<int, vector<int>> red_table, blue_table, used_red, used_blue;\n for(auto &edge : redEdges){\n red_table[edge[0]].push_back(edg...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<int>>adj[n];\n for(auto x: redEdges){\n adj[x[0]].push_back({x[1],0});\n }\n for(auto x: blueEdges){\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "\nclass Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) \n {\n multiset<int> temp;\n vector<multiset<int>> redChilds(n, temp), blueChilds(n, temp);\n for(auto j : redEdges)\n {\n re...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "\nclass Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) \n {\n multiset<int> temp;\n vector<multiset<int>> redChilds(n, temp), blueChilds(n, temp);\n for(auto j : redEdges)\n {\n re...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n queue<pair<int,int>>q;\n q.push({0,-1});\n unordered_map<int,list<pair<int,int>>>adj;\n for(auto edge:redEdges){\n adj...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<int,vector<vector<int>>> graph;\n\n for(auto edges:redEdges) {\n graph[edges[0]].push_back({edges[1],0});\n }\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n string hashFn(pair<int, int> state) {\n return to_string(state.first) + \",\" + to_string(state.second);\n }\n\n int switchColor(int& color) {\n return 1 - color;\n }\n\n void fillGraph(int color, vector<vector<int>>& edges, unordered_map<int, vector...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<pair<int,int>>> v(n);\n map<vector<int>,int> m;\n\n for(auto i : redEdges){\n v[i[0]].push_back({i[1],0});\n }\n...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<int,vector<vector<int>>> graph;\n\n for(auto edges:redEdges) {\n graph[edges[0]].push_back({edges[1],0});\n }\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<int>> redAdj(n), blueAdj(n);\n vector<int> dis(n, -1);\n vector<vector<int>> redVis(n, vector<int>(n, 0)), blueVis(n, vector<int>(...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<string,vector<string > > adj;\n for(int i=0;i<redEdges.size();i++){\n string from=to_string(redEdges[i][0])+'b';\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<pair<int,int>>>adj(n);\n\n map<vector<int>,int>vis;\n for(auto it:redEdges){\n adj[it[0]].push_back({it[1],1});\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n string hashFn(pair<int, int> state) {\n return to_string(state.first) + \",\" + to_string(state.second);\n }\n\n int switchColor(int& color) {\n return 1 - color;\n }\n\n void fillGraph(int color, vector<vector<int>>& edges, unordered_map<int, unorde...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n string hashFn(pair<int, int> state) {\n return to_string(state.first) + \",\" + to_string(state.second);\n }\n\n int switchColor(int& color) {\n return 1 - color;\n }\n\n void fillGraph(int color, vector<vector<int>>& edges, unordered_map<int, unorde...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n \n\n // 0 red\n // 1 blue\n unordered_map<int,list<pair<int,int>>> adjList;\n for(auto &i : redEdges){\n adjList[i[0]...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\n pair<pair<int, int>, int> dist; // Stores node and distance traversed, and previously used colour\npublic:\n\n\n vector<int> answer;\n bool visited[101][2];\n void bfs(map<int, vector<int>> blueGraph, map<int, vector<int>> redGraph, int colour) {\n queue<pair<pair<int,...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<string, vector<string>> graph;\n graph.insert({ \"0r\", vector<string>() });\n graph.insert({ \"0b\", vector<string>() });\n\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n void bfs(unordered_map<int, vector<pair<int, int>>> &adj, vector<vector<int>> &visited, int source, vector<int> &distance) {\n\n queue<vector<int>> q;\n visited[source][0] = 1;\n visited[source][1] = 1;\n q.push({source, 0, -1});\n\n while(!...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\nvector<list<int> >redGraph;\nvector<list<int> >blueGraph;\nint f(int j,int n,deque<pair<int,int>>&pq){\n vector<bool>visitedRed(n,false);\n vector<bool>visitedBlue(n,false);\n visitedRed[0] = true;\n visitedBlue[0] = true;\n int ans = 0;\n while(!pq.empty()){\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, vector<int>> red_adj;\n unordered_map<int, vector<int>> blue_adj;\n int visited_red[101];\n int visited_blue[101];\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n for (int i...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\nprivate:\n int fun(int dest, vector<int> adjBlue[], vector<int> adjRed[],int n) {\n vector<int>distRed(n,INT_MAX);\n vector<int>distBlue(n,INT_MAX);\n distRed[0]=distBlue[0]=0;\n priority_queue<pair<int, pair<int, int>>,\n vector<pair<i...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\n int find_path(int dst, vector<vector<int>>& blueAdj, vector<vector<int>>& redAdj, bool isBlue, int n){\n int path = 0;\n queue<int> q;\n vector<bool> blueVisted(n, false);\n vector<bool> redVisted(n, false);\n q.push(0);\n while(!q.empty()){\n...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\n private:\n int bfs(int endNode, int n, unordered_map<int, vector<int>>& redAdjMat, unordered_map<int, vector<int>>& bluAdjMat) {\n vector<int> visitedRed(n, 0), visitedBlue(n, 0);\n\n queue<pair<int /*node*/, int /*color*/>> bfsQ; /*0->Red, 1->Blu*/\n bfsQ.push(...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n int cal(int s , int dest , vector<int> badj[], vector<int> radj[],int n)\n {\n vector<int>rvis(n ,0) , bvis(n , 0);\n\n queue<pair<pair<int,int>,int>> q;\n\n q.push({{ 0, 0 },-1 });\n rvis[0] = 1;\n bvis[0] = 1;\n while(!q.empty())...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n int cal(int s , int dest , vector<int> badj[], vector<int> radj[],int n)\n {\n vector<int>rvis(n ,0) , bvis(n , 0);\n\n queue<pair<pair<int,int>,int>> q;\n\n q.push({{ 0, 0 },-1 });\n rvis[0] = 1;\n bvis[0] = 1;\n while(!q.empty())...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "\n\n\n// get the shortest path from zero to each node with alternating color \nclass Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n // first build the graph \n vector<vector<pair<int, int>>> graph(n, vect...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<pair<int,int>> adj[n];\n for(auto x:redEdges){\n // if(x[0]==x[1]) continue;\n adj[x[0]].push_back({x[1],0});\n }\n...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<vector<pair<int, int>>> adjList; // 1 for red, 0 for blue\n int BFS(int target) {\n cout << endl << \"BFS FOR TARGET: \" << target << endl;\n map<pair<int, int>, bool> takenEdges;\n queue<pair<int, int>> q;\n q.push({0, -1});\n for...