package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/
 */
public class Problem1475 {
    public int[] finalPrices(int[] prices) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1475 prob = new Problem1475();
        System.out.println(Arrays.toString(prob.finalPrices(new int[]{8,4,6,2,3}))); // [4,2,4,2,3]
        System.out.println(Arrays.toString(prob.finalPrices(new int[]{1,2,3,4,5}))); // [1,2,3,4,5]
        System.out.println(Arrays.toString(prob.finalPrices(new int[]{10,1,1,6}))); // [9,0,1,6]
        System.out.println(Arrays.toString(prob.finalPrices(new int[]{1,2,3,4,1}))); // [0,1,2,3,1]
    }
}

package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/
 */
public class Problem1475 {
    public int[] finalPrices(int[] prices) {
        int[] answer = new int[prices.length];
        for (int i = 0; i < prices.length; i++) {
            int discount = 0;
            for (int j = i + 1; j < prices.length; j++) {
                if (prices[j] <= prices[i]) {
                    discount = prices[j];
                    break;
                }
            }
            answer[i] = prices[i] - discount;
        }
        return answer;
    }
}

Solve problem 1475