id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n template<typename P>\n bool topoIter(int n, vector<vector<int>> out, P&& job) {\n vector<int> in(n);\n for(int i = 0; i < n; ++i) \n for(const auto& j : out[i])\n ++in[j];\n queue<int> q{};\n for(int i = 0; i < n; ++i) ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n template<typename P>\n bool topoIter(int n, vector<vector<int>> out, P&& job) {\n // Calculate in order\n vector<int> in(n);\n for(int i = 0; i < n; ++i) \n for(const auto& j : out[i])\n ++in[j];\n // Topological sort\n... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "#include <vector>\n\nusing namespace std;\n\nclass Solution {\n vector<vector<int>> beforeGroups;\n vector<vector<int>> groupItems;\n vector<int> result;\n vector<bool> groupVisited;\n vector<bool> groupVisitedCurrentStack;\n vector<bool> itemVisited;\n vector<bool> itemVisitedCurrentS... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\n\npublic:\n vector<int> topologicalSort(vector<int>& inDegrees, vector<vector<int>>& graph) {\n stack<int> st;\n for (int i = 0; i < inDegrees.size(); i++) {\n if (inDegrees[i] == 0) {\n st.push(i);\n }\n }\n vector<int> ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n //create a graph for each group\n int indegree[n+m];\n memset(indegree,0,sizeof(indegree));\n vector<vector<int>>graph(n+m);\n for(int i = 0;i<n;i+... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<vector<int>> graph(n+m,vector<int>{});\n vector<int> indegree(n+m,0);\n vector<int> ans;\n for(int i=0; i<group.size();i++)\n {\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<vector<int>> graph(n+m,vector<int>{});\n vector<int> indegree(n+m,0);\n vector<int> ans;\n for(int i=0; i<group.size();i++)\n {\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int> grpIndegree(m);\n vector<vector<int>> graph(n);\n vector<vector<int>> groupGraph(m);\n queue<int> grpQueue;\n queue<int> itmQueue;\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int> grpIndegree(m);\n vector<vector<int>> graph(n);\n vector<vector<int>> groupGraph(m);\n for(int itm = 0, grp; itm < n;itm++ ){\n grp... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\n\npublic:\n vector<int> topologicalSort(vector<int>& inDegrees, vector<vector<int>>& graph) {\n stack<int> st;\n for (int i = 0; i < inDegrees.size(); i++) {\n if (inDegrees[i] == 0) {\n st.push(i);\n }\n }\n vector<int> ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector <int> ans;\n vector <int> adj[(m << 1) + n];\n vector <int> indegree(n + (m << 1));\n for(int i = 0; i < group.size(); ++i) {\n if(group... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n bool topo(vector<int>adj[],int n,vector<int>&res)\n {\n queue<int>qu;\n vector<int>ind(n,0);\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<adj[i].size();j++) ind[adj[i][j]]++;\n }\n for(int i=0;i<n;i++) if(!ind[i]) qu.push(... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n bool topo(vector<int>adj[],int n,vector<int>&res)\n {\n queue<int>qu;\n cout<<n<<endl;\n vector<int>ind(n,0);\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<adj[i].size();j++) ind[adj[i][j]]++;\n }\n for(int i=0;i<n;i... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& groups, vector<vector<int>>& beforeItems) {\n using i32 = int;\n vector <vector <i32>> A (n + m + m);\n vector <i32> deg (n + m + m);\n for (i32 i = 0; i < groups.size(); ++i) if (groups[i] != -1) {\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> toposort(vector<int> adj[], int k) {\n vector<int> indegree(k + 1);\n for (int i = 0; i < k; i++) {\n for (auto it : adj[i])\n indegree[it]++;\n }\n queue<int> q;\n vector<int> topo;\n for (int i ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int> t, res(n), state(n + 2 * m);\n vector<vector<int>> g(n + 2 * m);\n for (int i = 0; i < n; ++i) {\n if (group[i] != -1) {\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n bool CheckDAG(int u, vector<int> &color, const vector<vector<int>> &adj) { \n color[u] = 1; // Đang duyệt, đánh dấu màu là 1\n for(int v : adj[u]) {\n if(color[v] == 1) return true; // is DAG => res \n else if(color[v] == 0) {\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\n vector<int> topoSort(int sz, vector<vector<int>> &adj){\n vector<int> in(sz);\n vector<int> ans;\n for(int i = 0 ; i< sz; i++){\n for(auto node : adj[i]){\n in[node]++;\n }\n }\n\n queue<int> q;\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 0 | {
"code": "class Solution {\npublic:\nvoid f(vector<int> adj[],vector<int> &in,vector<int> &v){\n queue<int> q;\n int n=in.size();\n for(int i=0;i<n;i++){\n if(in[i]==0){\n q.push(i);\n }\n }\n while(!q.empty()){\n int node=q.front();\n q.pop();\n v.push_ba... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int> topologicalSort(vector<vector<int>>& graph, vector<int>& inDegree) {\n queue<int> q;\n for (int i = 0; i < inDegree.size(); i++) {\n if (inDegree[i] == 0) {\n q.push(i);\n }\n }\n vector<int> order;\... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n\n bool topo(vector<int> &ans,vector<int> mp[],vector<int> &in){\n queue<int> q;\n for(int i=0;i<in.size();i++){\n if(in[i]==0){\n q.push(i);\n }\n }\n\n while(!q.empty()){\n int u= q.front(); q.pop();\n ans.push_back... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int>topo(vector<vector<int>>& graph, vector<int>& indegree){\n vector<int>sorted;\n queue<int>q;\n\n for(int i=0; i<indegree.size(); i++){\n if(indegree[i]==0){\n q.push(i);\n }\n }\n while(!q.empty()){\n in... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int> topo_sort(vector<vector<int>>& adj ){\n // int count=0;\n // for(auto j:adj){\n // cout<<count++<<\" -> \";\n // for( auto i:j){\n // cout<<i<<\" \";\n // }\n // cout<<endl;\n // }\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\n vector<int> topologicalSort(vector<vector<int>> &graph, vector<int> indegree){\n vector<int> visited,stack,empty;\n for(int i = 0;i<graph.size();i++){\n if(indegree[i] == 0)stack.push_back(i);\n }\n\n while(!stack.empty()){\n int cur =... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n void dfs(int v,vector<bool>& vis,vector<int>& ans,vector<vector<int>>& g) {\n vis[v] = true;\n for (int u : g[v]) {\n if (!vis[u])\n dfs(u,vis,ans,g);\n }\n ans.push_back(v);\n }\n vector<int> topoSort(vector<vector<... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n for(int i = 0; i < n; i++){\n if (group[i] == -1) group[i] = m++;\n }\n\n vector<unordered_set<int>> groupGraph(m, unordered_set<int>());\n vec... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int> toposort(int n,vector<int> adj[], vector<int> &indegree){\n vector<int> ans;\n queue<int> q;\n for(int i=0; i<n; i++){\n if(indegree[i]==0){\n q.push(i);\n }\n }\n while(!q.empty()){\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "#include <ranges>\n\ntemplate <typename T> concept Callback = invocable<T, int>;\n\nclass Solution {\npublic:\n template<ranges::range R, ranges::range R2, Callback F>\n bool toposort(R& g, vector<int>& deg, const vector<R2>& edge, F& op) {\n int count = 0, total = 0;\n vector<int> stac... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int> topoSort(unordered_map<int,list<int>>& adjList,vector<int>& inDegree)\n {\n int n = inDegree.size();\n queue<int> q;\n for(int i = 0 ; i < n ; i++)\n if(inDegree[i] == 0)\n q.push(i);\n\n vector<int> ans;\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n bool topoSort(vector<vector<int>> adj ,vector<int> &topo,vector<int> °){\n queue<int> q;\n for(int i=0;i<deg.size();i++){\n if(deg[i]==0)\n q.push(i);\n }\n while(!q.empty()){\n int curr=q.front();\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int> toposort(unordered_map<int, vector<int>>& adj, vector<int>& indegree) {\n queue<int> q;\n for (int i = 0; i < indegree.size(); i++) {\n if (indegree[i] == 0) q.push(i);\n }\n vector<int> ans;\n while (!q.empty()) {\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 1 | {
"code": "class Solution {\npublic:\n vector<int>toposort(unordered_map<int,vector<int>>& adj,vector<int>& indegree){\n queue<int>q;\n for(int i=0;i<indegree.size();i++){\n if(indegree[i]==0) q.push(i);\n }\n vector<int>ans;\n while(!q.empty()){\n int node=... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n vector<int> topSort(int n, map<int, vector<int>>& adj, vector<int>& indegree) {\n queue<int> q;\n vector<int> sorted;\n for (int i = 0; i < n; ++i) {\n if (indegree[i] == 0) {\n q.push(i);\n }\n }\n while... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n vector<int> topoSort(vector<vector<int>>& adj, vector<int>& inDegree) {\n queue<int> q;\n for(int i = 0; i < inDegree.size(); i++) {\n if (inDegree[i] == 0) q.push(i);\n }\n vector<int> res;\n while(!q.empty()) {\n int ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "#include <ranges>\n\nclass Solution {\npublic:\n template<ranges::range R, ranges::range R2>\n bool toposort(R& g, vector<int>& deg, vector<R2>& edge, function<bool(int)> op) {\n int count = 0, total = 0;\n vector<int> stack;\n\n for (auto x: g) {\n if (deg[x] == 0) st... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "#include <ranges>\n\nclass Solution {\npublic:\n template<ranges::range R, ranges::range R2, typename T>\n bool toposort(R& g, vector<int>& deg, const vector<R2>& edge, T op) {\n int count = 0, total = 0;\n vector<int> stack;\n\n for (auto x: g) {\n if (deg[x] == 0) st... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n\n vector<int> topoSort(unordered_map<int, vector<int>>& neighbourMap, vector<int>& inDegree){\n queue<int> q; // contains nodes whose dependency have been resolved, aka indeg = 0\n for(pair<int, vector<int>> p : neighbourMap){\n if(inDegree[p.first] =... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n vector<int>topo(unordered_map<int,list<int>>&adj,vector<int>&indegree){\n queue<int>q;\n for(int i=0;i<indegree.size();i++){\n if(indegree[i]==0)q.push(i);\n }\n vector<int>ans;\n while(!q.empty()){\n int front=q.fron... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n for(int i=0;i<group.size();i++){\n if(group[i]==-1)group[i]=m++;\n }\n map<int,vector<int>> mp;\n for(int i=0;i<group.size();i++)group[i]++;\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n vector<int> bfs(queue<int> &q, unordered_map<int, vector<int>>& adj, unordered_map<int, int>& indegree){\n vector<int> ans;\n while(!q.empty()){\n int top = q.front();\n q.pop();\n\n for(auto nbr: adj[top]){\n inde... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n unordered_map<int, int> groupOf;\n int totalGroups = m;\n for(int i = 0; i < n; i++){\n if (group[i] == -1) {\n groupOf[i] = totalGroup... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 2 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n for(int i = 0; i < n; ++i)\n if(group[i] == -1)\n group[i] = m++;\n\n vector<unordered_set<int>> graphGroup(m), graphItem(n);\n vector<... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n //vector<vector<int>> member(m, vector<int>());\n unordered_set<int> member[m];\n for (int i = 0; i < n; i++) {\n if (group[i] > -1) {\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> khansalgo(unordered_map<int,vector<int>>m,vector<int>count){\n vector<int>result;\n queue<int>q;\n for(int i=0;i<count.size();i++){\n if(count[i]==0){\n q.push(i);\n }\n }\n while(!q.empty()){... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n static bool cmp(vector<int>&a,vector<int>&b)\n {\n if(a[0]!=b[0])return a[0]<b[0];\n else return a[1]<b[1];\n }\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int>graph[n];\n vector<i... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\n vector<int> topological_sort(const vector<vector<int>>& graph) {\n vector<int> vec;\n vector<int> visited(graph.size());\n int cnt = 1;\n\n auto dfs = [&](int v, int cnt, auto Dfs) -> bool {\n visited[v] = -cnt;\n for (int u : graph[v]... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\n vector<int> topological_sort(const vector<vector<int>>& graph) {\n vector<int> vec;\n vector<int> visited(graph.size());\n int cnt = 1;\n\n auto dfs = [&](int v, int cnt, auto Dfs) -> bool {\n visited[v] = -cnt;\n for (int u : graph[v]... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n unordered_map<int, vector<int>> groups;\n int id = 30001;\n for (int i = 0; i < n; ++i) {\n if (group[i] == -1) {\n groups[id].push_bac... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n unordered_map<int, vector<int>> groups;\n int id = 30001;\n for (int i = 0; i < n; ++i) {\n if (group[i] == -1) {\n groups[id].push_bac... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\nvector<int>topoSort(unordered_map<int,vector<int>>adj,vector<int>& indegree)\n{\nqueue<int>que;\nfor(int i=0;i<adj.size();i++)\n{\n if(indegree[i]==0)\n {\n que.push(i);\n }\n}\n vector<int>result;\n while(!que.empty())\n {\n int u=que.front();\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n\n bool topoSortUtil(vector<int>& topoOrder, unordered_map<int,int>& indeg, unordered_map<int,vector<int>>& graph){\n priority_queue<int,vector<int>, greater<int>> minHeap;\n for(auto &i: indeg) if(!i.second) minHeap.push(i.first);\n int cnt=0;\n wh... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n unordered_map<int,int>inner_group;\n unordered_map<int,vector<int>>outter_group;\nvector<int> inner_item(n);\nvector<vector<int>> outter_item(n);\nunordered_map<int,ve... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n int idx = m;\n vector<vector<int>>groupItems(m);\n for(int i=0;i<n;i++) {\n if(group[i] == -1) {\n groupItems.push_back({});\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& G, vector<vector<int>>& B) {\n vector<unordered_set<int>> A(n + 2 * m);\n vector<int> D(n + 2 * m), v;\n stack<int> sk;\n for(int i = 0; i < n; ++i)\n {\n if(G[i] != -1)\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n bool topSort(vector<unordered_set<int>>& al, int i, vector<int>& res, vector<int>& stat) {\n if (stat[i] != 0) return stat[i] == 2;\n stat[i] = 1;\n for (auto n : al[i])\n if (!topSort(al, n, res, stat)) return false;\n stat[i] = 2;\n res.push_back(i);\n... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n bool topSort(vector<unordered_set<int>>& al, int i, vector<int>& res, vector<int>& stat) {\n if (stat[i] != 0) return stat[i] == 2;\n stat[i] = 1;\n for (auto n : al[i])\n if (!topSort(al, n, res, stat)) return false;\n stat[i] = 2;\n res.push_back(i);\n... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int> ans;\n vector<vector<int>> groups(m + 1 );\n vector<vector<int>> graph(n);\n vector<int> items_dep(n, 0);\n vector<int> group_dep(m + 1... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int> ans;\n vector<vector<int>> groups(m );\n vector<vector<int>> graph(n);\n vector<int> items_dep(n, 0);\n vector<int> group_dep(m , 0);\n... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& groups, vector<vector<int>>& beforeItems) {\n unordered_map<int,int> groups_indegree;\n unordered_map<int,vector<int>> groups_graph;\n unordered_map<int,int> num_items_in_groups;\n unordered_map<int,... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& groups, vector<vector<int>>& beforeItems) {\n unordered_map<int,int> groups_indegree;\n unordered_map<int,vector<int>> groups_graph;\n unordered_map<int,int> num_items_in_groups;\n unordered_map<int,... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n int flag=0;\n vector<int> fin_ans;\n int d1[100010]={0};\n int d2[100010]={0};\n void toposort(map<int,vector<int>> & grp,int g,vector<vector<int>> &adj_e){\n queue<int> q;\n for(auto x:grp[g]){\n if(d1[x]==0) q.push(x);\n }\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int> nodeIndegree(n);\n vector<int> adj[n];\n unordered_map<int, int> groupIndegree;\n unordered_map<int, unordered_set<int>> groupAdj;\n un... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> adj[100005], ele[100005];\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n vector<int> in(n+2,0), vis(n+2,0);\n\n for(int i = 0; i<n; i++){\n if(group[i] >= 0){\n ele[group[i... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n map<int, vector<int>> grp_mem;\n vector<vector<int>> sub_ord;\n\n void topo_sort(int grp_ind, vector<vector<int>>& bfr, vector<vector<int>>& sorted_grp, vector<int>& in_degree) {\n queue<int> q;\n for (auto mem : grp_mem[grp_ind]) {\n if (in_deg... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n void kaln( int node , map< int, map<int,vector<int>> > &gig , vector<int> &ans ){\n map<int,vector<int>> mp = gig[node];\n map<int,int> indegree;\n for( auto v : mp ){\n for( auto i : v.second ){\n indegree[i]++;\n }\... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\n vector<int> getTopoSort(vector<unordered_set<int>> &adj,vector<int> &nodes,vector<int> &indeg){\n int n=nodes.size();\n vector<int> topo;\n // unordered_map<int,int> vis;\n queue<int> q;\n for(auto it:nodes){\n if(indeg[it]==0){\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& G, vector<vector<int>>& B) {\n unordered_map<int, unordered_set<int>> A;\n vector<int> D(n + 2 * m), v;\n stack<int> sk;\n for(int i = 0; i < n; ++i)\n {\n if(G[i] != -1)\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> getItemsTopo(map<int, vector<int>>& adjList, map<int, set<int>>& groupMap, int groupNum) {\n map<int, int> indegreeMap;\n for(auto node : groupMap[groupNum]) {\n indegreeMap[node] = 0;\n }\n\n for(auto node : groupMap[groupNu... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> getItemsTopo(map<int, vector<int>>& adjList, map<int, set<int>>& groupMap, int groupNum) {\n map<int, int> indegreeMap;\n for(auto node : groupMap[groupNum]) {\n indegreeMap[node] = 0;\n }\n\n for(auto node : groupMap[groupNu... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n // treat no group as unique groups\n // run two topological sorts\n int mx = 0;\n for (int i = 0; i < group.size(); i++) {\n mx = max(mx, group... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> adj;\n vector<int> in, head, tail, order;\n void topsort(int s){\n int n = adj.size();\n queue<int> q;\n q.push(s);\n while(q.size()){\n int u = q.front(); q.pop();\n order.push_back(u);\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> adj;\n vector<int> in, head, tail, order;\n void topsort(int s){\n int n = adj.size();\n queue<int> q;\n q.push(s);\n while(q.size()){\n int u = q.front(); q.pop();\n order.push_back(u);\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& G, vector<vector<int>>& B) {\n unordered_map<int, unordered_set<int>> A;\n unordered_map<int, int> D;\n vector<int> v;\n stack<int> sk;\n for(int i = 0; i < n; ++i)\n {\n D[i... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n std::unordered_multimap<int, int> group_map;\n std::unordered_multimap<int, int> group_adj_map;\n std::unordered_multimap<int, int> node_adj_map;\n void createNodeAdjMap(const vector<vector<int>>& beforeItems){\n for(int i = 0; i < beforeItems.size(); i++) {\n... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n void fun(int g,vector<int>& grp,vector<int>& inDeg,vector<vector<int>>& adj,vector<int>& topoSort,vector<int>& vec){\n queue<int> q;\n int n=grp.size();\n for(int i: vec){\n // cout<<i<<\" \";\n if(inDeg[i]==0){\n q.pu... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic: \n vector<int> topSort(map<int, vector<int>> &adjList){\n map<int, int> inDeg;\n for(auto it: adjList){\n if(inDeg.count(it.first) == 0) inDeg[it.first] = 0;\n for(int neigh: it.second)\n ++inDeg[neigh];\n }\n\n q... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n int groupId = m;\n map<int, set<int>> groupSet;\n\n for(int i=0; i<n; i++){\n if(group[i]==-1){\n group[i] = (groupId++);\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> topSort(unordered_map<int, vector<int>> &adj) {\n int N = adj.size();\n\n unordered_map<int, int> indegree;\n for(auto entry: adj)\n indegree[entry.first] = 0;\n for(auto entry: adj) {\n int u = entry.first;\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> topoSort(vector<vector<int>> &edges, int n){\n vector<vector<int>> graph(n);\n vector<int> indegree(n);\n\n for (auto edge : edges){\n graph[edge[0]].push_back(edge[1]);\n indegree[edge[1]]++;\n }\n\n queue<... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n int groupId = m;\n map<int, set<int>> groupItem;\n\n for(int i=0;i<n;i++){\n if(group[i]==-1){\n group[i]=(groupId++);\n }\n... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n inline int encode(int n, int grpIdx, int i) {\n return (grpIdx == -1) ? i : (n + grpIdx);\n }\n\n vector<int> topoSort(unordered_map<int, vector<int>>& edges, unordered_map<int, int>& inDeg) {\n queue<int> q;\n for (auto& p : inDeg) {\n i... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic: \n vector<int> topSort(unordered_map<int, vector<int>> &adjList){\n unordered_map<int, int> inDeg;\n for(auto it: adjList){\n if(inDeg.count(it.first) == 0) inDeg[it.first] = 0;\n for(int neigh: it.second)\n ++inDeg[neigh];\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic: \n vector<int> topSort(unordered_map<int, vector<int>> &adjList){\n unordered_map<int, int> inDeg;\n for(auto it: adjList){\n if(inDeg.count(it.first) == 0) inDeg[it.first] = 0;\n for(int neigh: it.second)\n ++inDeg[neigh];\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) \n {\n unordered_map<int, unordered_set<int>>groupItems;\n int nextGroupId = m;\n\n for (int i=0; i<n; i++)\n {\n if (group[i]==-1)\n ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n \n unordered_map<int, unordered_set<int>> groups;\n unordered_map<int, unordered_set<int>> graph;\n unordered_map<int, int> indegree;\n\n int ngsf ... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n unordered_map<int, set<int>> groupGraph;\n unordered_map<int, vector<int>> groupAndItems;\n unordered_map<int, int> itemAndGroup;\n int idxNewGroup = m;\n for(int i = 0;... |
1,309 | <p>There are <code>n</code> items each belonging to zero or one of <code>m</code> groups where <code>group[i]</code> is the group that the <code>i</code>-th item belongs to and it's equal to <code>-1</code> if the <code>i</code>-th item belongs to no group. The items and the group... | 3 | {
"code": "class Solution {\npublic:\n vector<int> sortItems(int n, int m, vector<int>& group, vector<vector<int>>& beforeItems) {\n \n unordered_map<int, unordered_set<int>> groups;\n unordered_map<int, unordered_set<int>> graph;\n unordered_map<int, int> indegree;\n\n int ngsf ... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n sort(arr.begin(),arr.end());\n int ans[70];\n int k=0;\n for(int i=1;i<arr.size();i++)\n {\n int j=1;\n while(arr[i]==arr[i-1]&&i<arr.size()-1)\n {\n ... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n sort(arr.begin(), arr.end());\n unordered_set<int> seen;\n \n int cnt = 0;\n\n int i=0;\n int j=0;\n for (i; j<arr.size(); j++) {\n if (arr[i] != arr[j]) {\n ... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n vector<int> occurrences;\n sort(arr.begin(), arr.end());\n int count = 1;\n for (int i = 0; i < arr.size() - 1; i++)\n {\n if (arr[i] == arr[i + 1])\n count++;\n e... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n \n vector<int> ans;\n\n\n for(int i=0;i<arr.size();i++){\n int temp=arr[i];\n if(temp==-2333) continue;\n int cnt=1;\n for(int j=i+1;j<arr.size();j++){\n ... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n std::vector<int> values;\n std::vector<int> counts;\n\n\n for (int i=0; i < arr.size(); i++)\n {\n auto j = std::find(values.begin(), values.end(), arr[i]);\n\n if (j == values.end(... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n \n int n=arr.size();\n \n vector<int> ans;\n sort(arr.begin(),arr.end());\n for(int i=0;i<n;)\n { \n int c=1;\n for(int j=i+1;j<n;j++)\n {\n ... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n vector<int> ans;\n int size = arr.size();\n sort(arr.begin(),arr.end());\n int i = 0;\n while(i<size){\n int count = 1;\n for(int j = i+1;j<size;j++){\n if (a... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n vector<int> ans;\n int size =arr.size();\n sort(arr.begin(),arr.end());\n int i =0;\n while(i<size){\n int count =1;\n for(int j = i+1; j<size; j++){\n if(arr[... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n vector<int> res;\n\n sort(arr.begin(), arr.end());\n for(int i = 0; i < arr.size(); i++)\n {\n int count = 0;\n while((i+1) < arr.size() && arr[i] == arr[i+1])\n {\n ... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n sort(arr.begin(),arr.end());\n vector<int>ans;\n for(int i=0; i<arr.size(); i++){\n int cnt = 1;\n while(i+1 < arr.size() && arr[i] == arr[i+1]){\n cnt++;\n i... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n map<int, int> m;\n for(int value : arr) {\n if (m.find(value) == m.cend()) {\n m.insert({value, 1});\n } else {\n m[value] = m[value] + 1;\n }\n }\... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n // unordered_map\n map<int,int> m;\n for (int i = 0; i < arr.size(); i++) {\n if (m.find(arr[i]) != m.end()) {\n m[arr[i]] += 1; \n } else {\n m[arr[i]] = 1;\... |
1,319 | <p>Given an array of integers <code>arr</code>, return <code>true</code> <em>if the number of occurrences of each value in the array is <strong>unique</strong> or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> arr = [1,2,2... | 0 | {
"code": "class Solution {\npublic:\n bool uniqueOccurrences(vector<int>& arr) {\n unordered_map<int, int> counts;\n\n for (const auto& num : arr) {\n counts[num] += 1;\n }\n \n unordered_set<int> uniqueCounts;\n for (const auto& [val, count] : counts) {\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.