class RecipeCart:
The round: a Decagon phone screen coding question in seven reports from May to September 2026. The detailed reports share the same Part 1, a shopping cart whose discount depends on ingredient counts. The second part differs: three reports got undo and redo, one got versions with checkout, and one got nested begin, commit and abort. This page grades all three as Parts 2, 3 and 4; in the round expect one of them. Four graded parts, each tab a complete RecipeCart.
Given — what the tests call
In the round the recipes and discounts are given as globals; reports do not remember whether as lists or maps. Here they are dicts passed to the constructor, and the sample data RECIPES and DISCOUNTS is given:
RECIPES = {"Chicken Parm": ["Chicken", "Garlic", "Tomato", "Cheese"], ...}
DISCOUNTS = {"Garlic": [(2, 3), (4, 8)], ...} # (threshold, dollars off)
class RecipeCart:
def __init__(self, recipes: dict, discounts: dict): ...
def add_recipe(self, recipe_name: str) -> None: ...
def remove_recipe(self, recipe_name: str) -> None: ...
def get_total_discount(self) -> int: ...
Part 1 — the cart and its bulk discount
add_recipe(recipe_name) adds a recipe; no-op if it is already in the cart. remove_recipe(recipe_name) removes it; no-op if it is not in the cart. At most one of each recipe is in the cart.get_total_discount() returns the total discount in dollars.[(2, 3), (4, 8)]: 0-1 recipes with Garlic give $0 off, 2-3 give $3, 4 or more give $8. Only the highest tier met applies.Notes: the class name RecipeCart, the constructor taking the data, the dict formats, the sample recipes and their tiers (beyond Garlic's) are ours. So are: an ingredient listed twice in one recipe counting once, an unknown recipe raising ValueError, a no-op making no version, checkout itself making no new version, get_version returning the number, commit with no open transaction being a no-op, and an inner commit folding into the outer transaction (so an outer abort still undoes it). The reports do not cover these; ask in the round.
Seven reports from May to September 2026, all phone screens; one calls it the frequent Decagon screen question. The detailed reports share the same Part 1 cart, and the statement comes as a docstring with the API and the Garlic example. The second part varies by interviewer: undo and redo is the most common, one candidate got versions with checkout, and one got nested begin, commit and abort, which that candidate approached like database transactions. In the versions round the candidate first wanted to store every version and the interviewer asked for a space-efficient history of operations instead; that interviewer gave many hints. For this round itself: two candidates passed it and moved on toward the onsite; two finished the problem (one says every test passed) and were rejected the next day; the other three give no result for this round, one of them being rejected after a second screen with a different question. Several describe interviewers who were distracted, and one round ended after 30 minutes when the interviewer left.
Common mistakes: Adding discount tiers together instead of taking the highest one met.; Recording a no-op add or remove on the undo stack (one report says a test checks this).; Storing a full copy of the cart for every version when the interviewer wants a space-efficient history.
What candidates did: One candidate made the internal add and remove return whether they changed the cart and only then touched the undo and redo stacks. One stored the version history as (add, name) and (remove, name) operations and replayed them from the start on checkout, which is what the interviewer asked for. One treated nested begin, commit and abort like database transactions.
What candidates say: Two finished the problem (one says every test passed) and were rejected the next day; two candidates guessed the bar is about communication or fit as much as the code.
Also reported as Cooking App Cart · Shopping Cart with Undo and Redo
The round: a Decagon phone screen coding question in seven reports from May to September 2026. The detailed reports share the same Part 1, a shopping cart whose discount depends on ingredient counts. The second part differs: three reports got undo and redo, one got versions with checkout, and one got nested begin, commit and abort. This page grades all three as Parts 2, 3 and 4; in the round expect one of them. Four graded parts, each tab a complete RecipeCart.
Given — what the tests call
In the round the recipes and discounts are given as globals; reports do not remember whether as lists or maps. Here they are dicts passed to the constructor, and the sample data RECIPES and DISCOUNTS is given:
RECIPES = {"Chicken Parm": ["Chicken", "Garlic", "Tomato", "Cheese"], ...}
DISCOUNTS = {"Garlic": [(2, 3), (4, 8)], ...} # (threshold, dollars off)
class RecipeCart:
def __init__(self, recipes: dict, discounts: dict): ...
def add_recipe(self, recipe_name: str) -> None: ...
def remove_recipe(self, recipe_name: str) -> None: ...
def get_total_discount(self) -> int: ...
Part 1 — the cart and its bulk discount
add_recipe(recipe_name) adds a recipe; no-op if it is already in the cart. remove_recipe(recipe_name) removes it; no-op if it is not in the cart. At most one of each recipe is in the cart.get_total_discount() returns the total discount in dollars.[(2, 3), (4, 8)]: 0-1 recipes with Garlic give $0 off, 2-3 give $3, 4 or more give $8. Only the highest tier met applies.Part 2 — undo and redo
undo() reverses the most recent operation. redo() re-applies the most recently undone one. A new add or remove clears the redo history. undo() or redo() with nothing to do is a no-op.get_total_discount() reflects the state after any undos and redos.Part 3 — versions and checkout
{A}, add B makes version 2 {A, B}.get_version() returns the current version number. checkout(version) goes back to that version and discards every later one: after checkout(1), version 2 is gone and the next operation makes a new version 2.("add", name) or ("remove", name), and rebuild by replaying them from the start.Part 4 — begin, commit and abort
begin() starts a transaction. Adds and removes after it apply right away: get_total_discount() includes uncommitted changes.commit() keeps the changes. abort() undoes every change not yet committed; with no open transaction it is a no-op.begin() can be called again inside a transaction. Commit and abort then apply to the innermost one only: begin, add A, begin, add B, abort leaves A in the cart.Notes: the class name RecipeCart, the constructor taking the data, the dict formats, the sample recipes and their tiers (beyond Garlic's) are ours. So are: an ingredient listed twice in one recipe counting once, an unknown recipe raising ValueError, a no-op making no version, checkout itself making no new version, get_version returning the number, commit with no open transaction being a no-op, and an inner commit folding into the outer transaction (so an outer abort still undoes it). The reports do not cover these; ask in the round.
Add undo() and redo(). A new operation resets the redo history; undo or redo with nothing to do is a no-op.
Make sure an add or remove that changed nothing is not recorded for undo.
Every operation makes a new version. Add get_version and checkout(version), which discards every later version.
Can you store the version history in a space-efficient way?
Add begin, commit and abort. begin can nest, and commit or abort applies to the innermost begin only.
Common mistakes: Adding discount tiers together instead of taking the highest one met.; Recording a no-op add or remove on the undo stack (one report says a test checks this).; Storing a full copy of the cart for every version when the interviewer wants a space-efficient history.
What candidates did: One candidate made the internal add and remove return whether they changed the cart and only then touched the undo and redo stacks. One stored the version history as (add, name) and (remove, name) operations and replayed them from the start on checkout, which is what the interviewer asked for. One treated nested begin, commit and abort like database transactions.
What candidates say: Two finished the problem (one says every test passed) and were rejected the next day; two candidates guessed the bar is about communication or fit as much as the code.
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 8 Decagon questions, refreshed monthly from new candidate reports.