← 返回 ramp 的题目列表OA — Digital Recipe Manager (4 Levels)
类型:qbank
A CodeSignal four-level OA: a recipe manager with CRUD and case-insensitive name uniqueness, ingredient search and sorting, user accounts/edits, and per-recipe version history with rollback.
Requirements
A four-level recipe manager (1.5-hour limit). Each level unlocks after all tests pass; efficiency not graded.
Level 1 — CRUD
add_recipe(name, ingredients: list[str], steps: list[str]) -> str | None — returns "recipe" + id (sequential from 1). Returns None if a recipe with the same name (case-insensitive) exists.
get_recipe(recipe_id) -> list[str] — returns [name, ingredients_as_string, steps_as_string] (ingredients/steps comma-joined, ingredients in original order), or [] if missing.
update_recipe(recipe_id, name, ingredients, steps) -> bool — True on success; False if missing or the new name conflicts (case-insensitive) with another recipe.
delete_recipe(recipe_id) -> bool — True if it existed.
Level 2 — Search & sort
search_recipes_by_ingredient(ingredient) -> list[str] — recipe ids containing ingredient (case-insensitive), sorted by ingredient count asc, then recipe id asc.
list_recipes(sort_by) -> list[str] — all ids sorted by "name" (lexicographic asc) or "ingredient_count" (asc); tie-break recipe id asc; invalid sort_by defaults to name.
Level 3 — Users & edits
add_user(user_id) -> bool — False if user exists.
edit_recipe(user_id, recipe_id, new_name, new_ingredients, new_steps) -> bool — any user can edit any recipe; enforces case-insensitive name uniqueness; False if the user/recipe is missing or the name conflicts.
Level 4 — Version control
version_recipe(recipe_id) -> list[str] — each entry "<version>:<name>:<ingredients_as_string>:<steps_as_string>:<last_edited_by>", sorted by version asc. Returns [] if the recipe is missing or was never edited. Recipes created via add_recipe have no version history until the first edit; history is created on edit_recipe / update_recipe.
Notes
Name uniqueness is case-insensitive at every level — keep a normalized-name index so add/update/edit all share the same conflict check.
Level 4 only records history starting at the first edit, and stamps each version with the editing user; design Level 1's storage so a version snapshot is cheap to append rather than reconstructed later.
Preparation
Implement Levels 1–2 with the exact comma-join output format and the dual sort keys, testing case-insensitive name collisions.
Add users and versioning, snapshotting (name, ingredients, steps, editor) on each edit and reproducing the version:name:...:editor string format exactly.