A fuel station logs n daily prices, one per day, in order. For each day, find the number of days you must wait until a later day whose price is strictly cheaper than the current day's price. If no later day is cheaper, report 0 for that day.
Line 1: an integer n.
Line 2: n space-separated integers, the daily prices in order.
n space-separated integers on one line: the number of days to wait for each day, in the same order.
Example 1
Input
5 30 40 20 25 10
Expected
2 1 2 1 0
Explanation
Day 30: the first later cheaper day is the 20 two days ahead, so 2. Day 40: the 20 is one day ahead, so 1. Day 20: the next cheaper is the 10 two days ahead, so 2. Day 25: the 10 is one day ahead, so 1. Day 10: no later day is cheaper, so 0.
Example 2
Input
3 10 20 30
Expected
0 0 0
Explanation
Prices only rise, so no day is ever followed by a cheaper day: every answer is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →