Company: Microsoft
Difficulty: medium
Final Prices With a Special Discount in a Shop Problem Description A shopkeeper arranges items in a list for sale. Starting from the left, each item is sold at its full price minus the price of the first item to its right that is equal or lower. If no such item exists, the current item is sold at its full price. The final price of an item cannot be negative; if the calculated discounted price is less than zero, it should be considered zero (i.e., max(0, original_price - discount_value) ). Complete the function `finalPrice`. It takes an integer array `prices` as input. Instead of returning a value, the function should print two lines: The first line should contain the total cost of all items. The second line should contain a space-separated list of 0-based indices of items that were sold at their full price, in ascending order. Examples Example 1: Input: prices = [5, 1, 3, 4, 6, 2] Output: 14 1 5 Explanation: The prices of the items are given by the array: prices = [5, 1, 3, 4, 6, 2] We