2025-08-03 13:56:55 +0300 MSK
Final Prices With a Special Discount in a Shop
Links
Code
class Solution:
def finalPrices(self, prices: List[int]) -> List[int]:
stack = deque()
for i in range(len(prices)):
price = prices[i]
while True:
if not stack:
break
last_i, last_price = stack[-1]
if last_price >= price:
prices[last_i] -= price
stack.pop()
else:
break
stack.append((i, price))
return prices