Design receipt system with combo discounts
Problem Description
You are tasked with building a point-of-sale (POS) ordering user interface (UI). You are provided with several class stubs:
Item(id, name, price)Menu(lookupById)Order(add, remove, quantities)Display(show)- A callback function:
onUserUpdateSelected(itemId)
Part A: Basic Receipt Generation
Each time the onUserUpdateSelected(itemId) callback is invoked, you must perform the following actions:
- Add the specified item to the current
Orderinstance. - Update the quantities of items within the
Order. - Generate and print a receipt string using
Display.show(receipt). The receipt must adhere to the following format:- Each line item should be displayed as:
<name> x <qty> @ <unitPrice> = <lineTotal> - The line items should be followed by a
subtotaland agrand total.
- Each line item should be displayed as:
Your implementation for Part A should include the necessary data structures and toString/formatting logic to correctly handle repeated additions of the same item and multiple distinct items.
Part B: Combo Discount System
Extend the system to incorporate combo discounts. A Combo is defined by the following attributes:
requiredCount k: The number of items required for the combo.eligibleItemIds or categories: A list of specific item IDs or categories that qualify for the combo.discountValue: The discount amount, which can be of type{amountOff | percentOff}.
After each update (i.e., after onUserUpdateSelected is called and Part A's receipt is generated), you must:
- Identify any valid set of non-overlapping combos that can be applied to the current
Order. - Compute the discounted total. Note: You are not required to maximize the discount or the number of combos applied; any valid application is acceptable.
- Output which combos were applied and the final discounted total on the receipt.
For Part B, you need to:
- Describe your data model for combos.
- Describe the algorithm used to pick a valid set of non-overlapping combos (e.g., backtracking or greedy with backtracking fallback).
- State the time and space complexity of your solution.
- State any reasonable assumptions you make (e.g., unique item IDs, integer quantities, rounding rules).
AI interview prep
Core dilemma
The central engineering conflict is balancing the correctness and efficiency of state management (order items, quantities, applied combos) with the complexity of applying non-overlapping, rule-based discounts after every single item update. The 'any valid set' constraint simplifies the optimization problem but still requires careful algorithmic design for combo matching and item consumption.
3 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design receipt system with combo discounts
Problem Description
You are tasked with building a point-of-sale (POS) ordering user interface (UI). You are provided with several class stubs:
Item(id, name, price)Menu(lookupById)Order(add, remove, quantities)Display(show)- A callback function:
onUserUpdateSelected(itemId)
Part A: Basic Receipt Generation
Each time the onUserUpdateSelected(itemId) callback is invoked, you must perform the following actions:
- Add the specified item to the current
Orderinstance. - Update the quantities of items within the
Order. - Generate and print a receipt string using
Display.show(receipt). The receipt must adhere to the following format:- Each line item should be displayed as:
<name> x <qty> @ <unitPrice> = <lineTotal> - The line items should be followed by a
subtotaland agrand total.
- Each line item should be displayed as:
Your implementation for Part A should include the necessary data structures and toString/formatting logic to correctly handle repeated additions of the same item and multiple distinct items.
Part B: Combo Discount System
Extend the system to incorporate combo discounts. A Combo is defined by the following attributes:
requiredCount k: The number of items required for the combo.eligibleItemIds or categories: A list of specific item IDs or categories that qualify for the combo.discountValue: The discount amount, which can be of type{amountOff | percentOff}.
After each update (i.e., after onUserUpdateSelected is called and Part A's receipt is generated), you must:
- Identify any valid set of non-overlapping combos that can be applied to the current
Order. - Compute the discounted total. Note: You are not required to maximize the discount or the number of combos applied; any valid application is acceptable.
- Output which combos were applied and the final discounted total on the receipt.
For Part B, you need to:
- Describe your data model for combos.
- Describe the algorithm used to pick a valid set of non-overlapping combos (e.g., backtracking or greedy with backtracking fallback).
- State the time and space complexity of your solution.
- State any reasonable assumptions you make (e.g., unique item IDs, integer quantities, rounding rules).