AO
Back

Recipe Shopping Cart with Ingredient Bulk Discounts

Also reported as Cooking App Cart · Shopping Cart with Undo and Redo

Phone ScreenPhone ScreenLast reported September 2026Medium Frequency

Problem Overview

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

  • Users add recipes to their cart. Each recipe has a list of ingredients. When the same ingredient appears in several recipes in the cart, its count can reach a 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.
  • Reported example: Chicken Parm and Stir Fry both contain Garlic, so the cart holds Garlic at quantity 2. Garlic's tiers are [(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.
  • A no-op add or remove is not an operation: it must not go on the undo stack. One report says a test checks exactly this.

Part 3 — versions and checkout

  • Every add or remove makes a new version. Version 0 is the empty cart: add A makes version 1 {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.
  • The interviewer asked for a space-efficient history. Storing a copy of the cart per version was not accepted: store the operations, ("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.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 5
Trade-off discussion

Add undo() and redo(). A new operation resets the redo history; undo or redo with nothing to do is a no-op.

Probes for: after Part 1, the most common second part

Make sure an add or remove that changed nothing is not recorded for undo.

Probes for: during the undo and redo part; one report says a test checks it

Every operation makes a new version. Add get_version and checkout(version), which discards every later version.

Probes for: after Part 1, in one report instead of undo and redo

Can you store the version history in a space-efficient way?

Probes for: the candidate proposes storing every version

Add begin, commit and abort. begin can nest, and commit or abort applies to the innermost begin only.

Probes for: after Part 1, in one report instead of undo and redo

What Reports Emphasize

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.

Practice

Write your own against 17 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Decagon with friends?

Send them this page. It is free to read, no account needed.

More Decagon Questions

Free preview

Every question in the Decagon catalog gets this depth

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.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Decagon · Phone Screen · Reported 7× across candidate reports
Is this helpful?