Free written solutionFinal Prices With a Special Discount in a Shop (LeetCode 1475): Solution and Explanation
Each item gets a discount equal to the price of the first later item that costs the same or less. Return what you pay for every item. For [8,4,6,2,3] the answer is [4,2,4,2,3].
Read the intuition, approach, code and complexity →