|
| 1 | +<h2><a href="https://leetcode.com/problems/find-all-possible-recipes-from-given-supplies">Find All Possible Recipes from Given Supplies</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><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>. A recipe can also be an ingredient for <strong>other </strong>recipes, i.e., <code>ingredients[i]</code> may contain a string that is in <code>recipes</code>.</p> |
| 2 | + |
| 3 | +<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> |
| 4 | + |
| 5 | +<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> |
| 6 | + |
| 7 | +<p>Note that two recipes may contain each other in their ingredients.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> recipes = ["bread"], ingredients = [["yeast","flour"]], supplies = ["yeast","flour","corn"] |
| 14 | +<strong>Output:</strong> ["bread"] |
| 15 | +<strong>Explanation:</strong> |
| 16 | +We can create "bread" since we have the ingredients "yeast" and "flour". |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong class="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>Input:</strong> recipes = ["bread","sandwich"], ingredients = [["yeast","flour"],["bread","meat"]], supplies = ["yeast","flour","meat"] |
| 23 | +<strong>Output:</strong> ["bread","sandwich"] |
| 24 | +<strong>Explanation:</strong> |
| 25 | +We can create "bread" since we have the ingredients "yeast" and "flour". |
| 26 | +We can create "sandwich" since we have the ingredient "meat" and can create the ingredient "bread". |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p><strong class="example">Example 3:</strong></p> |
| 30 | + |
| 31 | +<pre> |
| 32 | +<strong>Input:</strong> recipes = ["bread","sandwich","burger"], ingredients = [["yeast","flour"],["bread","meat"],["sandwich","meat","bread"]], supplies = ["yeast","flour","meat"] |
| 33 | +<strong>Output:</strong> ["bread","sandwich","burger"] |
| 34 | +<strong>Explanation:</strong> |
| 35 | +We can create "bread" since we have the ingredients "yeast" and "flour". |
| 36 | +We can create "sandwich" since we have the ingredient "meat" and can create the ingredient "bread". |
| 37 | +We can create "burger" since we have the ingredient "meat" and can create the ingredients "bread" and "sandwich". |
| 38 | +</pre> |
| 39 | + |
| 40 | +<p> </p> |
| 41 | +<p><strong>Constraints:</strong></p> |
| 42 | + |
| 43 | +<ul> |
| 44 | + <li><code>n == recipes.length == ingredients.length</code></li> |
| 45 | + <li><code>1 <= n <= 100</code></li> |
| 46 | + <li><code>1 <= ingredients[i].length, supplies.length <= 100</code></li> |
| 47 | + <li><code>1 <= recipes[i].length, ingredients[i][j].length, supplies[k].length <= 10</code></li> |
| 48 | + <li><code>recipes[i], ingredients[i][j]</code>, and <code>supplies[k]</code> consist only of lowercase English letters.</li> |
| 49 | + <li>All the values of <code>recipes</code> and <code>supplies</code> combined are unique.</li> |
| 50 | + <li>Each <code>ingredients[i]</code> does not contain any duplicate values.</li> |
| 51 | +</ul> |
0 commit comments