← 返回 airbnb 的题目列表Recipe Management System
类型:online_judge
Problem: Recipe Management System
Implement a RecipeManagementSystem class that manages recipes and users. A recipe ID has the format "recipe" + id, where id is a monotonically increasing integer starting from 1. Deleted recipe IDs must not be reused.
Level 1: Basic Recipe Management
Implement:
add_recipe(name: str, ingredients: list[str], steps: list[str]) -> str | None
Add a recipe and return its ID.
Recipe names are unique case-insensitively.
Return None if a recipe with the same name already exists ignoring case.
Otherwise, create the recipe and return its new ID, such as "recipe1".
get_recipe(recipe_id: str) -> list[str]
Return:
[name, ingredients_as_string, steps_as_string]
Join ingredients and steps using ,, preserving their original input order.
Return [] if the recipe does not exist.
update_recipe(recipe_id: str, name: str, ingredients: list[str], steps: list[str]) -> bool
Update a recipe.
Return True on success.
Return False if the recipe does not exist or if the new name conflicts case-insensitively with another recipe.
Updating a recipe while retaining its own name is valid.
delete_recipe(recipe_id: str) -> bool
Delete a recipe and return whether it existed.
Level 2: Search and Listing
search_recipes_by_ingredient(ingredient: str) -> list[str]
Return IDs of all recipes containing the given ingredient, matched case-insensitively.
Sort by ingredient count ascending.
Break ties by recipe ID ascending.
list_recipes(sort_by: str) -> list[str]
Return all recipe IDs.
For "ingredient_count", sort by ingredient count ascending, then recipe ID ascending.
For "name", sort by recipe name lexicographically, then recipe ID ascending.
Invalid values default to "name".
Level 3: Users and Editing
add_user(user_id: str) -> bool
Add a user. Return True if newly added and False if the user already exists.
edit_recipe(user_id: str, recipe_id: str, new_name: str, new_ingredients: list[str], new_steps: list[str]) -> bool
An existing user may edit any existing recipe; there are no permission restrictions.
Return True only if the user and recipe both exist and the new name does not conflict case-insensitively with another recipe. Otherwise return False.
Constraints
Up to 10^5 total method calls.
A recipe can contain up to 10^3 ingredients and steps.
Example
Input
add_recipe("Pasta", ["Tomato", "Salt"], ["Boil", "Serve"])
get_recipe("recipe1")
Output
"recipe1"
["Pasta", "Tomato,Salt", "Boil,Serve"]