A greenhouse control system logs n daily temperature readings, one per day, in order. Temperatures may be negative (below freezing). For each day, find the number of days you must wait until a later day whose reading is strictly warmer than the current day's reading. If no such later day exists, report 0 for that day.
Line 1: an integer n.
Line 2: n space-separated integers, the daily temperature readings 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
4 68 70 72 65
Expected
1 1 0 0
Explanation
Day 0 (68): 1 day later (70) is warmer. Day 1 (70): 1 day later (72) is warmer. Day 2 (72): no later day is warmer. Day 3 (65): no later day exists.
Example 2
Input
3 80 75 70
Expected
0 0 0
Explanation
Temperatures strictly cool down every day, so it never warms up again after any day.
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 →