Fresh off the OA, just did it. I'm saying I definitely failed because I only passed two levels. I wrote level 3 but a few test cases wouldn't pass, and I never even got to see level 4. The problem itself isn't hard, but there are a ton of corner cases, and you need every single test case to pass before you can move on to the next level. I also feel like this is a brand new question bank, because none of the interview reports I've seen so far overlap with this one. But in the spirit of sharing after the interview, I'll share it anyway — maybe it'll help someone who runs into the same question.
Recipe Management System
Level 1
-
add_recipe(self, name: str, ingredients: list[str], steps: list[str]) -> str | None
Add a new recipe and return its recipe_id.
The recipe_id format is"recipe" + id, where id is an auto-incrementing integer starting from 1.
If a recipe with the same name (case-insensitive) already exists, return None. -
get_recipe(self, recipe_id: str) -> list[str]
Get the recipe for the given recipe_id.
Return a string array[name, ingredients_as_string, steps_as_string], where ingredients_as_string and steps_as_string are the ingredients list and steps list joined into strings with commas; if the recipe doesn't exist, return an empty array.
The returned ingredients order must match the order passed into add_recipe. -
update_recipe(self, recipe_id: str, name: str, ingredients: list[str], steps: list[str]) -> bool
Update the recipe for the given recipe_id.
Return True if the update succeeds; return False if the recipe doesn't exist, or if the new name conflicts with another existing recipe (case-insensitive). -
delete_recipe(self, recipe_id: str) -> bool
Delete the specified recipe. Return True if the recipe exists (deletion succeeds), otherwise return False.
Level 2
-
search_recipes_by_ingredient(self, ingredient: str) -> list[str]
Return the recipe_id list of all recipes that contain the given ingredient (case-insensitive).
Sorting rule: sort ascending by the recipe's ingredient count first, then by recipe ID ascending when counts are equal. -
list_recipes(self, sort_by: str) -> list[str]
Return the recipe_id list of all recipes.
sort_by can be "name" or "ingredient_count":
When sorted by "ingredient_count", sort ascending by ingredient count, then by recipe ID ascending when counts are equal.
When sorted by "name", sort names lexicographically, then by recipe ID ascending when names are equal.
If sort_by is an invalid value, default to sorting by "name".
Level 3
-
add_user(self, user_id: str) -> bool
Add a new user. Return True if the add succeeds; return False if the user already exists. -
edit_recipe(self, user_id: str, recipe_id: str, new_name: str, new_ingredients: list[str], new_steps: list[str]) -> bool
Allow a user to edit a recipe.
Any user can edit any recipe (no permission restrictions).
Name uniqueness (case-insensitive) still has to be maintained.
If the edit succeeds, return True (assuming the user exists).
If the user doesn't exist, the recipe doesn't exist, or the new name conflicts with another existing recipe (case-insensitive), return False.
Discussion
Loading comments…