2115. Find All Possible Recipes from Given Supplies Medium
1/**
2 * [2115] Find All Possible Recipes from Given Supplies
3 *
4 * 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.
5 * 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.
6 * Return a list of all the recipes that you can create. You may return the answer in any order.
7 * Note that two recipes may contain each other in their ingredients.
8 *
9 * Example 1:
10 *
11 * Input: recipes = ["bread"], ingredients = [["yeast","flour"]], supplies = ["yeast","flour","corn"]
12 * Output: ["bread"]
13 * Explanation:
14 * We can create "bread" since we have the ingredients "yeast" and "flour".
15 *
16 * Example 2:
17 *
18 * Input: recipes = ["bread","sandwich"], ingredients = [["yeast","flour"],["bread","meat"]], supplies = ["yeast","flour","meat"]
19 * Output: ["bread","sandwich"]
20 * Explanation:
21 * We can create "bread" since we have the ingredients "yeast" and "flour".
22 * We can create "sandwich" since we have the ingredient "meat" and can create the ingredient "bread".
23 *
24 * Example 3:
25 *
26 * Input: recipes = ["bread","sandwich","burger"], ingredients = [["yeast","flour"],["bread","meat"],["sandwich","meat","bread"]], supplies = ["yeast","flour","meat"]
27 * Output: ["bread","sandwich","burger"]
28 * Explanation:
29 * We can create "bread" since we have the ingredients "yeast" and "flour".
30 * We can create "sandwich" since we have the ingredient "meat" and can create the ingredient "bread".
31 * We can create "burger" since we have the ingredient "meat" and can create the ingredients "bread" and "sandwich".
32 *
33 *
34 * Constraints:
35 *
36 * n == recipes.length == ingredients.length
37 * 1 <= n <= 100
38 * 1 <= ingredients[i].length, supplies.length <= 100
39 * 1 <= recipes[i].length, ingredients[i][j].length, supplies[k].length <= 10
40 * recipes[i], ingredients[i][j], and supplies[k] consist only of lowercase English letters.
41 * All the values of recipes and supplies combined are unique.
42 * Each ingredients[i] does not contain any duplicate values.
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/find-all-possible-recipes-from-given-supplies/
48// discuss: https://leetcode.com/problems/find-all-possible-recipes-from-given-supplies/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn find_all_recipes(recipes: Vec<String>, ingredients: Vec<Vec<String>>, supplies: Vec<String>) -> Vec<String> {
54 vec![]
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_2115() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.