Shopping Cart Billing
Problem statement
An online store is holding a sale for its members. Every product has a retail price and may carry some discount tags. A member always pays the lowest price available for a product.
Each row products[i] describes one product:
products[i][0]is the retail price.- Every later entry is the name of a discount tag on that product, or
"EMPTY"for an unused slot.
Each row discounts[j] = [tag, type, amount] describes one discount tag. In the rules below, price is the product's retail price. There are three tag types:
The problem statement continues
ProExamples
Example 1
products = [["10","d0","d1"],["15","EMPTY","EMPTY"],["20","d1","EMPTY"]]discounts = [["d0","1","27"],["d1","2","5"]]return = 35- Product
0has retail price10. Tagd0gives10 * 73 / 100 = 7.3, which drops to7. Tagd1gives10 - 5 = 5. The lowest price is5. - Product
1has no tags, so it costs15. - Product
2has retail price20. Tagd1gives20 - 5 = 15, so it costs15.
The total is 5 + 15 + 15 = 35.
FastPrep Pro
Reported in 1 Amazon interview this weekUnlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$8.25/month
$99 billed yearly — or $19 month-to-month. Cancel anytime.
Free plan — 2 of 2 free unlocks used this week