The "Apply Discount Every n Orders interview question" is a system design and implementation task. You need to create a Cashier class for a store. This store has a special promotion: every customer gets a discount on their total bill. The class needs to store product prices and handle a getBill method that processes a customer's order and applies the discount if applicable.
Meta asks the "Apply Discount Every n Orders coding problem" to evaluate a candidate's ability to design a simple class and maintain internal state. It tests your proficiency with "Hash Table interview pattern" (for looking up product prices) and basic arithmetic (for calculating totals and percentages). It's a practical problem that mimics real-world point-of-sale systems.
This problem uses the Class Design and Hash Map patterns.
getBill is called.count % n == 0 to determine if the current customer is the customer. If so, apply the discount formula: total - (discount * total / 100).Store: n=3, Discount=50%. Prices: [Apples: 10, Bananas: 20]
getBill method where is total products and is items in order. A map makes it .counter % n == 0 is the safest way.Practice designing classes that store state. This is a common requirement for "Object-Oriented Design" or "System Implementation" interviews. Always choose the most efficient data structure for lookups, which is almost always a Hash Map.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Finding Pairs With a Certain Sum | Medium | Solve | |
| Unique Word Abbreviation | Medium | Solve | |
| Design Memory Allocator | Medium | Solve | |
| Dot Product of Two Sparse Vectors | Medium | Solve | |
| Simple Bank System | Medium | Solve |