Given the array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop, if you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum&nbsp;index such that j &gt; i and prices[j] &lt;= prices[i], otherwise, you will not receive any discount at all.

Return an array where the ith element is the final price you will pay for the ith item of the shop considering the special discount.

&nbsp;
Example 1:

Input: prices = [8,4,6,2,3]
Output: [4,2,4,2,3]
Explanation:&nbsp;
For item 0 with price[0]=8 you will receive a discount equivalent to prices[1]=4, therefore, the final price you will pay is 8 - 4 = 4.&nbsp;
For item 1 with price[1]=4 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 4 - 2 = 2.&nbsp;
For item 2 with price[2]=6 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 6 - 2 = 4.&nbsp;
For items 3 and 4 you will not receive any discount at all.


Example 2:

Input: prices = [1,2,3,4,5]
Output: [1,2,3,4,5]
Explanation: In this case, for all items, you will not receive any discount at all.


Example 3:

Input: prices = [10,1,1,6]
Output: [9,0,1,6]


&nbsp;
Constraints:


	1 &lt;= prices.length &lt;= 500
	1 &lt;= prices[i] &lt;= 10^3


class Solution:
    def finalPrices(self, prices: List[int]) -> List[int]:
        ## RC ##
        ## APPROACH : STACK ##
        ## LOGIC ## 
        ## 1. Use Monotonic Increasing Stack Concept
        ## 2. Main idea is to find the Next Smaller Element in O(N) using #1
        stack = []
        for i, num in enumerate(prices):
            while(stack and prices[stack[-1]] >= num):
                popIndex = stack.pop()
                prices[popIndex] -= num
            stack.append(i)
        return prices
class Solution {
    public int[] finalPrices(int[] prices) {
        for(int i = 0; i < prices.length; i++){
            for(int j = i + 1; j < prices.length; j++){
                if(j > i && prices[j] <= prices[i]){
                    prices[i] -= prices[j];
                    break;
                }
            }
        }
        return prices;
    }
}
class Solution {
public:
    vector<int> finalPrices(vector<int>& prices) {
        vector<int>sk;
        for(int i=0;i<prices.size();i++){
        int discount=prices[i];
            for(int j=i+1;j<prices.size();j++){
                if(prices[i]>=prices[j]){
                    discount=prices[i]-prices[j];
                    break;
                }

            }
            sk.push_back(discount);
        }
        return sk;
    }
};
var finalPrices = function(prices) {
    let adjPrices = [];
    while(prices.length) {
        let currentPrice = prices[0];
        
        // Remove first price in original array
        // Since we're looking for a price less than or equal to
        prices.shift();
        
        let lowerPrice = prices.find((a) => a <= currentPrice);
        adjPrices.push(lowerPrice ? currentPrice - lowerPrice : currentPrice);
    }
    
    return adjPrices;
};
Final Prices With a Special Discount in a Shop