From 73af78eff4deb9f57b9770a6565e10e3931259c2 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Fri, 21 Mar 2025 23:13:23 +0530 Subject: [PATCH] Create 2115. Find All Possible Recipes from Given Supplies --- ...d All Possible Recipes from Given Supplies | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 2115. Find All Possible Recipes from Given Supplies diff --git a/2115. Find All Possible Recipes from Given Supplies b/2115. Find All Possible Recipes from Given Supplies new file mode 100644 index 0000000..78e2a04 --- /dev/null +++ b/2115. Find All Possible Recipes from Given Supplies @@ -0,0 +1,31 @@ +class Solution { +public: +vector findAllRecipes(vector& recipes, vector>& ingredients, vector& supplies) { + unordered_set is_available(supplies.begin(), supplies.end()); + vector result; // final results + bool flag1 = true; // this current recipe added or not + + while(flag1){ + flag1 = false; + + for(int i = 0; i < recipes.size(); ++i){ + if(is_available.count(recipes[i]))continue; + + bool flag2 = true; + for(const string& ing : ingredients[i]){ + if (!is_available.count(ing)) { + flag2 = false; break; + } + } + + if(flag2){ + is_available.insert(recipes[i]); // further can used as supply + result.push_back(recipes[i]); + flag1 = true; + } + } + } + + return result; +} +};