Apply Discount Every n Orders LeetCode solution in Python

1
class Cashier:
2

3
def __init__(self, n: int, discount: int, products: List[int], prices: List[int]):
4

5
self.n = n
6
self.discount = discount
7
self.price = {}
8
self.customer = 0
9

10
for i in range(len(products)):
11
self.price[products[i]] = prices[i]
12

13
def getBill(self, product: List[int], amount: List[int]) -> float:
14

15
self.customer += 1
16

17
bill = 0
18

19
for i in range(len(product)):
20
bill += amount[i] * self.price[product[i]]
21

22
if self.customer == self.n:
23
bill = bill * (1 - self.discount / 100)
24
self.customer = 0
25

26
return bill
27

28

29
# Your Cashier object will be instantiated and called as such:
30
# obj = Cashier(n, discount, products, prices)
31
# param_1 = obj.getBill(product,amount)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0