Sequential Purchase Cost with Running-Minimum Discount
viaLeetCode
Given item prices to be purchased in the given order: the first item is bought at full price; for every subsequent item the discount applied equals the lowest price among all previously purchased items; a final item price cannot go below 0. Compute the total cost of buying all items. Track a running minimum of previous prices and sum max(price[i] - runningMin, 0). n up to 1e6.
asked …