Posts

2115. Find All Possible Recipes from Given Supplies

You have information about  n  different recipes. You are given a string array  recipes  and a 2D string array  ingredients . The  i th  recipe has the name  recipes[i] , and you can  create  it if you have  all  the needed ingredients from  ingredients[i] . Ingredients to a recipe may need to be created from  other  recipes, i.e.,  ingredients[i]  may contain a string that is in  recipes . You are also given a string array  supplies  containing all the ingredients that you initially have, and you have an infinite supply of all of them. Return  a list of all the recipes that you can create.  You may return the answer in  any order . Note that two recipes may contain each other in their ingredients.   Example 1: Input: recipes = ["bread"], ingredients = [["yeast","flour"]], supplies = ["yeast","flour","corn"] Output: ["bread"] Explanation: We can create "bread" since...

3108. Minimum Cost Walk in Weighted Graph

Image
There is an undirected weighted graph with  n  vertices labeled from  0  to  n - 1 . You are given the integer  n  and an array  edges , where  edges[i] = [u i , v i , w i ]  indicates that there is an edge between vertices  u i  and  v i  with a weight of  w i . A walk on a graph is a sequence of vertices and edges. The walk starts and ends with a vertex, and each edge connects the vertex that comes before it and the vertex that comes after it. It's important to note that a walk may visit the same edge or vertex more than once. The  cost  of a walk starting at node  u  and ending at node  v  is defined as the bitwise  AND  of the weights of the edges traversed during the walk. In other words, if the sequence of edge weights encountered during the walk is  w 0 , w 1 , w 2 , ..., w k , then the cost is calculated as  w 0  & w 1  & w 2  & ...