Design receipt system with combo discounts
CloudKitchensSoftware Engineer · Technical ScreenLast updated
A CloudKitchens software-engineer technical screen: build a point-of-sale order that prints an itemized receipt on every item tap, then extend it to apply combo discounts. It tests cart data-structure design, receipt formatting, and the algorithm for selecting a valid set of non-overlapping combos.
Question
You are building a point-of-sale ordering UI for a food-ordering workflow. You are given class stubs and a callback you must wire up:
Item(id, name, price)MenuwithlookupById(itemId)Orderwithadd,remove, and per-itemquantitiesDisplaywithshow(receipt)onUserUpdateSelected(itemId)— called by the framework each time the user taps an item
Part A — Incremental receipt. Each time onUserUpdateSelected(itemId) is called, add the item to the current Order, update its quantity, and print a receipt string via Display.show(receipt). The receipt must:
- List each line in the form
"<name> x <qty> @ <unitPrice> = <lineTotal>". - Print a subtotal and a grand total.
It must work correctly for repeated additions of the same item (quantities aggregate) and for multiple distinct items. Implement the data structures and the toString/formatting methods needed to support this.
Part B — Combo discounts. Extend the system to support combo discounts. A Combo is defined by:
- a required count
k(number of qualifying items needed to form one combo), - the set of eligible item IDs (or categories) that can satisfy it, and
- a discount value with a type, either
amountOff(flat amount) orpercentOff.
(In the simplest form a combo is just k items -> discountAmount.) After each item addition, find any valid set of non-overlapping combos that can be applied to the current Order, apply the resulting discount(s), and reprint the updated receipt showing which combos were applied and the final discounted total. You do not need to maximize the total discount or the number of combos — returning any valid application is sufficient.
In your answer, describe your data model for items, the cart/order, and combos; give pseudocode or code for onUserUpdateSelected; explain the algorithm you use to pick a valid set of non-overlapping combos (e.g., greedy with a backtracking fallback that guarantees a valid set if one exists); analyze the time and space complexity; and state your assumptions (e.g., unique item IDs, integer quantities, rounding rule for percentage discounts).
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.