Search⌘ K
AI Features

Solution: Final Prices With a Special Discount in a Shop

C# solution for the Final Prices With a Special Discount in a Shop problem using the Stacks pattern.

We'll cover the following...

Statement

You are given an integer array prices where prices[i] is the price of the ith item in a shop.

For each item i, find the smallest index j such that j>ij > i and prices[j] <= prices[i]. If such an index j exists, the discount for item i is prices[j], and the final price becomes prices[i] - prices[j]. If no such j exists, the final price for item i remains prices[i].

Return an array of the final prices for all items in the same order as prices.

Constraints:

  • ...