java.lang.Object
g2101_2200.s2115_find_all_possible_recipes_from_given_supplies.Solution

public class Solution extends Object
2115 - Find All Possible Recipes from Given Supplies.<p>Medium</p> <p>You have information about <code>n</code> different recipes. You are given a string array <code>recipes</code> and a 2D string array <code>ingredients</code>. The <code>i<sup>th</sup></code> recipe has the name <code>recipes[i]</code>, and you can <strong>create</strong> it if you have <strong>all</strong> the needed ingredients from <code>ingredients[i]</code>. Ingredients to a recipe may need to be created from <strong>other</strong> recipes, i.e., <code>ingredients[i]</code> may contain a string that is in <code>recipes</code>.</p> <p>You are also given a string array <code>supplies</code> containing all the ingredients that you initially have, and you have an infinite supply of all of them.</p> <p>Return <em>a list of all the recipes that you can create.</em> You may return the answer in <strong>any order</strong>.</p> <p>Note that two recipes may contain each other in their ingredients.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> recipes = [&ldquo;bread&rdquo;], ingredients = [[&ldquo;yeast&rdquo;,&ldquo;flour&rdquo;]], supplies = [&ldquo;yeast&rdquo;,&ldquo;flour&rdquo;,&ldquo;corn&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;bread&rdquo;]</p> <p><strong>Explanation:</strong> We can create &ldquo;bread&rdquo; since we have the ingredients &ldquo;yeast&rdquo; and &ldquo;flour&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> recipes = [&ldquo;bread&rdquo;,&ldquo;sandwich&rdquo;], ingredients = [[&ldquo;yeast&rdquo;,&ldquo;flour&rdquo;],[&ldquo;bread&rdquo;,&ldquo;meat&rdquo;]], supplies = [&ldquo;yeast&rdquo;,&ldquo;flour&rdquo;,&ldquo;meat&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;bread&rdquo;,&ldquo;sandwich&rdquo;]</p> <p><strong>Explanation:</strong></p> <p>We can create &ldquo;bread&rdquo; since we have the ingredients &ldquo;yeast&rdquo; and &ldquo;flour&rdquo;.</p> <p>We can create &ldquo;sandwich&rdquo; since we have the ingredient &ldquo;meat&rdquo; and can create the ingredient &ldquo;bread&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> recipes = [&ldquo;bread&rdquo;,&ldquo;sandwich&rdquo;,&ldquo;burger&rdquo;], ingredients = [[&ldquo;yeast&rdquo;,&ldquo;flour&rdquo;],[&ldquo;bread&rdquo;,&ldquo;meat&rdquo;],[&ldquo;sandwich&rdquo;,&ldquo;meat&rdquo;,&ldquo;bread&rdquo;]], supplies = [&ldquo;yeast&rdquo;,&ldquo;flour&rdquo;,&ldquo;meat&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;bread&rdquo;,&ldquo;sandwich&rdquo;,&ldquo;burger&rdquo;]</p> <p><strong>Explanation:</strong></p> <p>We can create &ldquo;bread&rdquo; since we have the ingredients &ldquo;yeast&rdquo; and &ldquo;flour&rdquo;.</p> <p>We can create &ldquo;sandwich&rdquo; since we have the ingredient &ldquo;meat&rdquo; and can create the ingredient &ldquo;bread&rdquo;.</p> <p>We can create &ldquo;burger&rdquo; since we have the ingredient &ldquo;meat&rdquo; and can create the ingredients &ldquo;bread&rdquo; and &ldquo;sandwich&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == recipes.length == ingredients.length</code></li> <li><code>1 <= n <= 100</code></li> <li><code>1 <= ingredients[i].length, supplies.length <= 100</code></li> <li><code>1 <= recipes[i].length, ingredients[i][j].length, supplies[k].length <= 10</code></li> <li><code>recipes[i], ingredients[i][j]</code>, and <code>supplies[k]</code> consist only of lowercase English letters.</li> <li>All the values of <code>recipes</code> and <code>supplies</code> combined are unique.</li> <li>Each <code>ingredients[i]</code> does not contain any duplicate values.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details