Recipe Management System
AirbnbOnline assessmentMedium
You are building a recipe manager as the class RecipeManagementSystem. Recipe ids are strings recipe1, recipe2, and so on, assigned in order of creation.
Part 1: Recipes with unique names
Implement:
add_recipe(name, ingredients, steps)creates a recipe and returns its id, or returnsnull, creating nothing, when a recipe with the same name already exists, ignoring case. Ids arerecipe1,recipe2, and so on in order of creation. Only a successful add takes a number, and a number is never used again, even after its recipe is deleted.get_recipe(recipe_id)returns[name, ingredients, steps]for the recipe, with the ingredients joined by","and the steps joined by","in their original order, or[]when the id does not exist.update_recipe(recipe_id, name, ingredients, steps)replaces all three fields and returnstrue. It returnsfalse, changing nothing, when the id does not exist or whennameis the name of another recipe, ignoring case. Keeping a recipe's own name, in any casing, is allowed.delete_recipe(recipe_id)deletes the recipe and returnstrue, or returnsfalsewhen the id does not exist. Its name can be used again afterwards.
Recipe ids are case sensitive.
- Example 1
- init
[]- operations
[["add_recipe",["Pasta",["Tomato","Salt"],["Boil","Serve"]]],["get_recipe",["recipe1"]],["add_recipe",["pasta",["Egg"],["Fry"]]],["add_recipe",["Soup",["Water"],["Heat"]]],["get_recipe",["recipe9"]],["update_recipe",["recipe1","PASTA",["Tomato"],["Boil"]]],["get_recipe",["recipe1"]],["update_recipe",["recipe1","soup",["Tomato"],["Boil"]]],["update_recipe",["recipe5","Other",["Tomato"],["Boil"]]],["delete_recipe",["recipe1"]],["delete_recipe",["recipe1"]],["get_recipe",["recipe1"]],["add_recipe",["Pasta",["Rice"],["Cook"]]],["get_recipe",["recipe3"]]]- Output
["recipe1",["Pasta","Tomato,Salt","Boil,Serve"],null,"recipe2",[],true,["PASTA","Tomato","Boil"],false,false,true,false,[],"recipe3",["Pasta","Rice","Cook"]]
Why: The first recipe gets
recipe1. Addingpastafails, because names are unique ignoring case, and it does not use up an id, soSoupisrecipe2. An unknown id reads as[]. A recipe may be updated to a different casing of its own name, but not to another recipe's name. Afterrecipe1is deleted, the namePastais free again and the new recipe getsrecipe3, notrecipe1.
Constraints
1 <= len(name) <= 32- Names, ingredients and steps use only ASCII letters, digits and spaces
0 <= len(ingredients) <= 10000 <= len(steps) <= 1000- At most
10^5calls in total
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.