← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given an integer array prices where prices[i] is the price of the ith item in a shop.
For each item, look for the first item to its right whose price is less than or equal to the current item's price. If such an item exists, that value is the discount for the current item. Otherwise, the item receives no discount.
Return an integer array answer where answer[i] is the final price you pay for the ith item after applying the discount.
Item 0 gets discount 4, item 1 gets discount 2, item 2 gets discount 2, and the last two items get no better qualifying discount.