Company: Visa_5_feb
Difficulty: medium
Market Discount Market Discount Description You're given a list of item prices from a market that runs an unusual discount scheme: The very first item is bought at its listed price, with no discount. For every item bought afterward, the discount applied equals the cheapest price among the items already bought. No item's final price can drop below 0. Items are bought strictly in the order given. Work out the total amount spent buying every item under this discount scheme. Examples Example 1: Input: prices = [2, 5, 1, 4] Output: 8 Explanation: The first item costs 2 (no discount yet). Items bought so far: [2]. The second item costs 5 - 2 = 3 (the cheapest item bought so far, [2], is 2). Items bought so far: [2, 5]. The third item costs max(1 - 2, 0) = 0 (the cheapest among [2, 5] is 2). Items bought so far: [2, 5, 1]. The fourth item costs 4 - 1 = 3 (the cheapest among [2, 5, 1] is 1). Total cost: 2 + 3 + 0 + 3 = 8 Example 2: Input: prices = [4, 9, 2, 3] Output: 10 Explanation: The first