Company: Microsoft_17july
Difficulty: medium
Calculate Amount Problem Description Alex has a list of items to purchase at a market. The owner offers to discount each item after the first one by the lowest marked price among the prior items. No item's price can be discounted below 0, and the list of items may not be reordered. Calculate the payable amount. The first item is never discounted and the minimum cost of any item is 0. Complete the function calculateAmount in the editor below. The function must return Alex's total cost to purchase all the items. calculateAmount has the following parameter(s): int prices[n] : the original prices of each of the items selected Returns: long int : the total cost to purchase the items after any discounts are applied Examples Example 1: Input: prices = [2, 5, 1, 4] Output: 8 Explanation: prices[0] = 2 . cost[0] = 2 because the first item is never discounted. prices[1] = 5 . The minimum prior price is prices[0] = 2 . So, cost[1] = 5 - 2 = 3 . prices[2] = 1 . The minimum prior price is min(price