2dbi

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.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account