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 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:
prices.length
prices[i]
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 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:
prices.length
prices[i]