Samsung Food: turn a recipe into the ingredients you actually need to buy
Samsung Food connects recipes, servings, and shopping lists. Its useful design step is the check before content becomes action: confirm portions, exclude ingredients already at home, then coordinate the shopping.
Break down the problem and try your own design and implementation first. Then explore the reasoning to check states, edge cases, trade-offs, and ways to test your approach. The guide offers a reasoning path, not a complete implementation.
Remove a dish without losing other shopping needs
Implement a shopping-requirements module for a local meal planner. Each dish has a unique ID; ingredients use consistent names and quantities are in grams. There is also a manual requirement, initially 50 grams of tomato, which is not edited in this task. Users can add or replace a dish’s ingredient requirements, remove a dish, and read shopping totals grouped by ingredient.
- Replacing a dish replaces all its old contributions; removing it removes only its contributions. Reading totals must not change any source. Ingredients with a zero total are omitted. Inputs are nonnegative integers. Removing a nonexistent dish leaves results unchanged.
- Add A: tomato 200 grams and egg 100 grams; add B: tomato 150 grams. Totals should be tomato 400 grams and egg 100 grams. Replace A with tomato 100 grams: the total is tomato 300 grams and egg disappears. Remove B: only tomato 150 grams remains. Remove B again: nothing changes.
- Deliver a runnable module and these calls. Explain how the data expresses who needs each ingredient and how that supports menu changes. No unit conversion, inventory, or real accounts are needed.
Explore the reasoning
Consider what is lost if you save only totals, especially when removing a dish. Keep recipe and manual sources independent, then decide whether totals are computed on demand or maintained during changes. Use replacement and repeated removal to check that one source never subtracts another source’s requirements.