Skip to content

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.

Medium#1357
LeetCode Problem

Apply Discount Every n Orders

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

Input
["Cashier","getBill","getBill","getBill"]
[[2,25,[4,7],[10,20]],[[4,7],[1,2]],[[7],[2]],[[4],[1]]]
Output
[null,50,30,10]
Explanation

The first bill is 50. The second subtotal 40 receives 25% off; the third is undiscounted.

Constraints

1 <= n <= 10^4; 0 <= discount <= 100
1 <= products.length <= 200; prices has matching length.
Product IDs are unique integers from 1 to 200; prices are 1 to 1000.
Each bill lists distinct existing product IDs with matching amounts from 1 to 1000.
At most 1000 bills; accepted error is at most 10^-5.

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.