Final Prices With a Special Discount in a Shop Problem
Final Prices With a Special Discount in a Shop Problem — ExecCode Easy DSA Practice
Solve the Final Prices With a Special Discount in a Shop problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an integer array prices where prices[i] is the price of the i^th item in a shop. Your task is to there is a special discount for items in the shop. If you buy the i^th item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i]. Otherwise, you will not receive any discount at all. Return an integer array answer where answer[i] is the final price you will pay for the i^th item of the shop, considering the special discount.
Examples
Input {"prices": [8, 4, 6, 2, 3]}; Output [4, 2, 4, 2, 3]. Input {"prices": [1, 2, 3, 4, 5]}; Output [1, 2, 3, 4, 5]
Constraints
1 <= prices.length <= 500 1 <= prices[i] <= 1000
Practice Final Prices With a Special Discount in a Shop free on ExecCode. Browse DSA problems, topic map, and placement guides.