4. Warmer Days
A weather monitoring system tracks daily temperatures in a database.
The meteorological team wants to identify days when the temperature was higher than the specific day.
Your task is to find all dates where the temperature was higher than the day before.
The company maintains a table named Weather with the following schema:
Table: Weather โโโโโโโโโโโโโโโฆโโโโโโโโโโโ โ Column Name โ Type โ โ โโโโโโโโโโโโโโฌโโโโโโโโโโโฃ โ id โ int โ โโโโโโโโโโโโโโโผโโโโโโโโโโโ โ recordDate โ date โ โโโโโโโโโโโโโโโผโโโโโโโโโโโ โ temperature โ int โ โโโโโโโโโโโโโโโฉโโโโโโโโโโโ
- id: A unique identifier (primary key) for each record.
- recordDate: The date when the temperature was recorded.
- temperature: The temperature recorded on that date.
Note - No two rows have the same recordDate.
You need to find the id of all dates where the temperature was higher than the previous day's temperature. The result can be returned in any order.
Example 1:
Example:
Input:
โโโโโโโโโโโโฆโโโโโโโโโโโโโฆโโโโโโโโโโโโโโ โ id โ recordDate โ temperature โ โ โโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฃ โ 1 โ 2023-06-01 โ 18 โ โโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโโโ โ 2 โ 2023-06-02 โ 22 โ โโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโโโ โ 3 โ 2023-06-03 โ 20 โ โโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโโโ โ 4 โ 2023-06-04 โ 28 โ โโโโโโโโโโโโฉโโโโโโโโโโโโโฉโโโโโโโโโโโโโโ
Output:
โโโโโโโโโโโโ โ id โ โ โโโโโโโโโโโฃ โ 2 โ โโโโโโโโโโโโ โ 4 โ โโโโโโโโโโโโ
Explanation:
- June 2 (id = 2) - 22ยฐC is higher than June 1โs 18ยฐC.
- June 3 (id = 3) - 20ยฐC is not higher than June 2โs 22ยฐC.
- June 4 (id = 4) - 28ยฐC is higher than June 3โs 20ยฐC.
Still unsure what the problem is asking ?
Letโs go through a few more examples, step by step, to make it clearer.