Implement Recipe Storage CRUD
CircleSoftware Engineer · Technical ScreenLast updated
This question evaluates the ability to design and implement in-memory data structures and APIs for CRUD operations, covering skills such as ID generation and parsing, string handling for case-insensitive uniqueness constraints, data modeling, and preserving original value casing.
Implement an in-memory RecipeStore that supports CRUD operations for recipes.
Each recipe contains:
id: a string identifier in the formrecipe<n>name: the recipe nameingredients: a list of stringssteps: a list of strings
Implement these methods:
create(name, ingredients, steps) -> stringget(recipeId) -> Recipe | nullupdate(recipeId, updatedRecipe) -> booldelete(recipeId) -> bool
Required behavior:
- IDs are assigned sequentially starting from 1 and exposed as
recipe1,recipe2, and so on. get,update, anddeletereceive the id as a string such asrecipe2. You must parse the numeric suffix to find the stored recipe. If the format is invalid, the operation fails.- Recipe names are unique in a case-insensitive way. For example,
PastaandpAsTashould be treated as the same logical name, so both cannot exist at the same time. - Preserve the stored casing of the name when returning a recipe. If a recipe was created as
PaSta,getmust returnPaSta. updatesucceeds only ifrecipeIdmatchesupdatedRecipe.id.- During
update, the name may change only by letter case. For example,PaStatopastais allowed, butPaStatoNoodlesis not. - If a case-only rename is accepted, future reads should return the new casing.
- Updating or deleting a non-existent recipe should fail.
Design appropriate data structures and implement the methods so common operations are efficient.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.