Practice Apply Discount Every n Orders
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Cashier(n,discount,products,prices) stores product prices. getBill(product,amount) totals price times quantity, applying discount percent to every nth bill: bills n, 2n, and so on. Other bills pay the full subtotal. Practice approach: Map product IDs to prices and increment a bill counter once per call. Apply (100-discount)/100 only when the counter is divisible by n, using floating-point division. Runtime is proportional to the number of purchased product types. Test n=1, zero discount, full discount, and the bill immediately after a discounted one.
Source: Apply Discount Every n Orders on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["Cashier","getBill","getBill","getBill"] [[2,25,[4,7],[10,20]],[[4,7],[1,2]],[[7],[2]],[[4],[1]]]
[null,50,30,10]
The first bill is 50. The second subtotal 40 receives 25% off; the third is undiscounted.
Constraints
Related LeetCode Problems
Practice more problems similar to Apply Discount Every n Orders.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.