Find All Possible Recipes from Given Supplies LeetCode solution in Python
1class Solution:2def findAllRecipes(3self, recipes: List[str], ingredients: List[List[str]], supplies: List[str]4) -> List[str]:56graph = defaultdict(list)7in_degree = defaultdict(int)8for r, ing in zip(recipes, ingredients):9for i in ing:10graph[i].append(r)11in_degree[r] += 11213queue = supplies[::]14res = []15while queue:16ing = queue.pop(0)17if ing in recipes:18res.append(ing)1920for child in graph[ing]:21in_degree[child] -= 122if in_degree[child] == 0:23queue.append(child)2425return res