Recipe Management System
Updated
Problem statement
You are building a small in-memory recipe manager. You get a list of operations, in order. Run each one and return one list of strings for every operation.
Recipe IDs are handed out in order: recipe1, recipe2, and so on. A deleted ID is never used again.
Recipe Operations
["ADD_RECIPE", name, ingredientsCsv, stepsCsv]: add a new recipe. Recipe names must be unique, ignoring case. Return[recipeId], or an empty list if a current recipe already has that name.["GET_RECIPE", recipeId]: return[name, ingredientsCsv, stepsCsv]. If the recipe does not exist, return an empty list.["UPDATE_RECIPE", recipeId, name, ingredientsCsv, stepsCsv]: replace the name, ingredients and steps. The same name rule applies. Return["true"]if it worked and["false"]if not. Each successful update adds a new version whose editor issystem.["DELETE_RECIPE", recipeId]: delete the recipe. Return["true"]if the recipe existed and["false"]if not.
Search and Users
["SEARCH_INGREDIENT", ingredient]: return the IDs of recipes that have this exact ingredient, ignoring case. Sort them by number of ingredients, fewest first. Break ties by the number in the recipe ID, smallest first.["LIST_RECIPES", sortBy]: return the IDs of all current recipes. Foringredient_count, sort by number of ingredients, then by the number in the ID. Forname, or any other value, sort by name ignoring case, then by the number in the ID.["ADD_USER", userId]: add a user. User IDs are case-sensitive. Return["true"]if the user was added and["false"]if that user already exists.["EDIT_RECIPE", userId, recipeId, name, ingredientsCsv, stepsCsv]: a user changes a recipe. Any existing user may edit any current recipe, and the same name rule applies. A successful edit adds a new version whose editor isuserId. Return["true"]on success and["false"]otherwise.
Version History
- A new recipe starts with no history. Each successful
UPDATE_RECIPE,EDIT_RECIPE, or rollback saves the full recipe as it is after the change. That copy becomes the next version. Versions are numbered from1. ["VERSION_RECIPE", recipeId]: return every version, oldest first, written asversion:name:ingredientsCsv:stepsCsv:lastEditedBy. Return an empty list if the recipe does not exist or has never been edited.["ROLLBACK_RECIPE", recipeId, version]: bring back the name, ingredients and steps from an existing version. Old versions never change. The restored recipe is saved as a new version whose editor isrollback. Return["false"]if the recipe or the version does not exist, or if the restored name clashes with another current recipe.
manageRecipes gets String[][] operations and returns String[][], with one inner list per operation.
Function
manageRecipes(operations: String[][]) → String[][]Examples
Example 1
operations = [["ADD_RECIPE","Pancakes","Flour,Egg,Milk","Mix,Cook"],["ADD_RECIPE","Salad","Lettuce,Tomato","Chop,Toss"],["GET_RECIPE","recipe1"],["SEARCH_INGREDIENT","egg"],["LIST_RECIPES","name"]]return = [["recipe1"],["recipe2"],["Pancakes","Flour,Egg,Milk","Mix,Cook"],["recipe1"],["recipe1","recipe2"]]The ingredient lookup is case-insensitive, so egg finds recipe1. Name order places Pancakes before Salad.
Example 2
operations = [["ADD_RECIPE","Soup","Water,Carrot","Boil,Serve"],["ADD_RECIPE","sOuP","Stock","Heat"],["UPDATE_RECIPE","recipe1","Stew","Potato,Beef,Carrot","Brown,Simmer"],["GET_RECIPE","recipe1"],["DELETE_RECIPE","recipe9"],["DELETE_RECIPE","recipe1"],["GET_RECIPE","recipe1"]]return = [["recipe1"],[],["true"],["Stew","Potato,Beef,Carrot","Brown,Simmer"],["false"],["true"],[]]Soup is added. Adding sOuP fails, because names ignore case, so it returns an empty list. The update replaces every field, and the next get shows the new Stew recipe. Deleting an ID that does not exist returns false. Deleting the stew works, so the last get returns an empty list. Deleting frees the name, but the ID is never used again.
Example 3
operations = [["ADD_RECIPE","Beta","X,Y","One,Two"],["ADD_RECIPE","Alpha","Z","Only"],["ADD_USER","chef"],["ADD_USER","chef"],["EDIT_RECIPE","missing","recipe1","Nope","X","Only"],["EDIT_RECIPE","chef","recipe1","Gamma","X","Only"],["LIST_RECIPES","ingredient_count"],["LIST_RECIPES","unsupported"]]return = [["recipe1"],["recipe2"],["true"],["false"],["false"],["true"],["recipe1","recipe2"],["recipe2","recipe1"]]Adding chef a second time fails. The edit by missing fails because that user does not exist. The edit by chef works. Now both recipes have one ingredient, so the ingredient-count list falls back to the number in the ID. The value unsupported is not a sort option, so the last list is sorted by name: Alpha comes before Gamma.
Example 4
operations = [["ADD_RECIPE","Soup","Water,Carrot","Boil,Serve"],["VERSION_RECIPE","recipe1"],["UPDATE_RECIPE","recipe1","Stew","Carrot,Potato","Chop,Simmer"],["ADD_USER","chef"],["EDIT_RECIPE","chef","recipe1","Curry","Spice,Potato","Toast,Simmer"],["VERSION_RECIPE","recipe1"],["ROLLBACK_RECIPE","recipe1","1"],["GET_RECIPE","recipe1"],["VERSION_RECIPE","recipe1"]]return = [["recipe1"],[],["true"],["true"],["true"],["1:Stew:Carrot,Potato:Chop,Simmer:system","2:Curry:Spice,Potato:Toast,Simmer:chef"],["true"],["Stew","Carrot,Potato","Chop,Simmer"],["1:Stew:Carrot,Potato:Chop,Simmer:system","2:Curry:Spice,Potato:Toast,Simmer:chef","3:Stew:Carrot,Potato:Chop,Simmer:rollback"]]The initial add creates no version. The system update and user edit create versions 1 and 2. Rolling back to version 1 restores Stew and appends version 3 without changing the earlier entries.
Constraints
1 <= operations.length <= 10^4.- Every operation is one of the kinds listed above and has exactly the values shown for it.
- Names, user IDs, ingredients, and steps use printable ASCII characters. Names and user IDs are never empty.
- Each ingredient and step is non-empty, has no commas or colons, and is at most
100characters long. Each CSV list has at most100items. - Recipe names are compared and sorted ignoring case. Ingredient matches also ignore case. User IDs are case-sensitive.
- A rollback version is a positive integer written with digits only and no leading zeroes. It fits in a signed 32-bit integer.
More Ramp interview questions
- Count Overlapping Square PairsOA · Seen Nov 2026
- Count User Mentions in Chat MessagesOA · Seen Nov 2026
- Accept or Decline QueriesOA · Seen Sep 2026
- Task Manager with Timed AssignmentsOA · Seen Jan 2026
- Bank Requests with Delayed CashbackOA · Seen Dec 2025
- Convert Snake Case Variables to Camel CaseOA · Seen Apr 2025
- Correct Apartment Bedroom CountsOA · Seen Feb 2025
- Retryable URL MazePHONE SCREEN · Seen Oct 2026
- Detect Recurring Transactions with Tunable TolerancesONSITE INTERVIEW · Seen Jul 2026
- Find a User’s Airport from Flight HistoryPHONE SCREEN · Seen Sep 2025
Similar questions at other companies
- In-Memory File SystemAirbnb · OAAirbnb interview questions
- Power Cell BankOptiver · OAOptiver interview questions
- Four-Level Banking System with Scheduled PaymentsZipRecruiter · OAZipRecruiter interview questions
- Task Management SystemCoinbase · OACoinbase interview questions
- Task Management SystemAnthropic · OAAnthropic interview questions
- Progressive Parcel Tracking OperationsKlaviyo · OAKlaviyo interview questions
- Versioned Recipe SystemThe Trade Desk · OA
- Document and Layer OperationsFigma · OAFigma interview questions
- Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
- Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions