Skip to content

Commit 41dd81e

Browse files
committed
2115. Find All Possible Recipes from Given Supplies: RETRY
1 parent bccd0e2 commit 41dd81e

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,3 +1596,4 @@ mod s2109_adding_spaces_to_a_string;
15961596
mod s2110_number_of_smooth_descent_periods_of_a_stock;
15971597
mod s2111_minimum_operations_to_make_the_array_k_increasing;
15981598
mod s2114_maximum_number_of_words_found_in_sentences;
1599+
mod s2115_find_all_possible_recipes_from_given_supplies;
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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]. A recipe can also be an ingredient for 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+
*/
45+
pub 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+
52+
impl Solution {
53+
pub fn find_all_recipes(
54+
recipes: Vec<String>,
55+
ingredients: Vec<Vec<String>>,
56+
supplies: Vec<String>,
57+
) -> Vec<String> {
58+
vec![]
59+
}
60+
}
61+
62+
// submission codes end
63+
64+
#[cfg(test)]
65+
mod tests {
66+
use super::*;
67+
68+
#[test]
69+
#[ignore]
70+
fn test_2115_example_1() {
71+
let recipes = vec_string!["bread"];
72+
let ingredients = vec![vec_string!["yeast", "flour"]];
73+
let supplies = vec_string!["yeast", "flour", "corn"];
74+
75+
let result = vec_string!["bread"];
76+
77+
assert_eq!(
78+
Solution::find_all_recipes(recipes, ingredients, supplies),
79+
result
80+
);
81+
}
82+
83+
#[test]
84+
#[ignore]
85+
fn test_2115_example_2() {
86+
let recipes = vec_string!["bread", "sandwich"];
87+
let ingredients = vec![vec_string!["yeast", "flour"], vec_string!["bread", "meat"]];
88+
let supplies = vec_string!["yeast", "flour", "meat"];
89+
90+
let result = vec_string!["bread"];
91+
92+
assert_eq!(
93+
Solution::find_all_recipes(recipes, ingredients, supplies),
94+
result
95+
);
96+
}
97+
98+
#[test]
99+
#[ignore]
100+
fn test_2115_example_3() {
101+
let recipes = vec_string!["bread", "sandwich", "burger"];
102+
let ingredients = vec![
103+
vec_string!["yeast", "flour"],
104+
vec_string!["bread", "meat"],
105+
vec_string!["sandwich", "meat", "bread"],
106+
];
107+
let supplies = vec_string!["yeast", "flour", "meat"];
108+
109+
let result = vec_string!["bread", "sandwich", "burger"];
110+
111+
assert_eq!(
112+
Solution::find_all_recipes(recipes, ingredients, supplies),
113+
result
114+
);
115+
}
116+
}

0 commit comments

Comments
 (0)