category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

2115. Find All Possible Recipes from Given Supplies, topological sorting, medium, implementation

Code implementation ```cpp vector findAllRecipes(vector &recipe, vector<vector> &ingredients, vector &supplies) { map<string, vector> graph; set supply_set; for (auto &x : supplies) supply_set.insert(x); map<string, int> indegree; for (auto &x : recipe) indegree[x] = 0; int n = recipe.size(); for (int i = 0; i < n; i++) { for (int j = 0; j < ingredients[i].size(); j++) { auto supply_finder = supply_set.find(ingredients[i][j]); if (supply_finder == supply_set.end()) { graph[ingredients[i][j]].push_back(recipe[i]); indegree[recipe[i]]++; } } } queue qu; for (auto x : indegree) if (x.second == 0) qu.push(x.first); vector topo; while (!qu.empty()) { string u = qu.front(); qu.pop(); topo.push_back(u); for (auto &v : graph[u]) { indegree[v]--; if (indegree[v] == 0) qu.push(v); } } return topo; } ``` </details>