Hone logo
Hone
Problems

Rising Temperature

You are given a table of daily temperatures. Your task is to identify days where the temperature is warmer than the previous day. This is a fundamental data analysis task that helps in understanding weather patterns and trends.

Problem Description

You will be provided with a table (or list of records) named Weather containing daily temperature readings. The table has two columns: id (a unique identifier for the day, typically an integer) and temperature (the temperature recorded on that day, an integer).

Your goal is to find all days where the temperature is strictly greater than the temperature recorded on the immediately preceding day. You should return the id of these days.

Key Requirements:

  • Compare the temperature of a given day with the temperature of the previous day.
  • The comparison must be a strict inequality (i.e., temperature > previous_temperature).
  • Return only the ids of the days that meet the condition.
  • The input ids are assumed to be in chronological order.

Expected Behavior:

For each day in the Weather table, check if its temperature is higher than the temperature of the day with the preceding id. If it is, include the current day's id in the result.

Edge Cases:

  • First day: The first day in the table has no preceding day, so it cannot be warmer than the previous day. It should not be included in the results.
  • Empty table: If the Weather table is empty, no days can satisfy the condition, and the output should be empty.
  • Single day table: If the table contains only one day, there is no previous day to compare with, so the output should be empty.

Examples

Example 1:

Input:
Weather table:
| id  | temperature |
|-----|-------------|
| 1   | 10          |
| 2   | 12          |
| 3   | 9           |
| 4   | 15          |
| 5   | 13          |
| 6   | 17          |

Output:
| id  |
|-----|
| 2   |
| 4   |
| 6   |

Explanation:
- Day 2 (temp 12) is warmer than Day 1 (temp 10).
- Day 3 (temp 9) is not warmer than Day 2 (temp 12).
- Day 4 (temp 15) is warmer than Day 3 (temp 9).
- Day 5 (temp 13) is not warmer than Day 4 (temp 15).
- Day 6 (temp 17) is warmer than Day 5 (temp 13).

Example 2:

Input:
Weather table:
| id  | temperature |
|-----|-------------|
| 1   | 5           |
| 2   | 5           |
| 3   | 6           |

Output:
| id  |
|-----|
| 3   |

Explanation:
- Day 2 (temp 5) is not strictly warmer than Day 1 (temp 5).
- Day 3 (temp 6) is strictly warmer than Day 2 (temp 5).

Example 3 (Edge Case):

Input:
Weather table:
| id  | temperature |
|-----|-------------|
| 10  | 20          |

Output:
(Empty result)

Explanation:
There is only one day, so no previous day exists for comparison.

Constraints

  • The id column is an integer and represents a unique day identifier.
  • The temperature column is an integer.
  • The number of rows in the Weather table will be between 0 and 1000 (inclusive).
  • Temperatures will be between -100 and 100 (inclusive).
  • The ids are guaranteed to be positive integers and are in strictly increasing order, representing chronological order.
  • The solution should be efficient. A solution with a time complexity of O(N) where N is the number of rows in the table is expected.

Notes

  • Think about how you can access the "previous" record for each record.
  • Consider using techniques that allow you to join a table with itself or to access lagged values.
  • Ensure your solution handles the first record correctly.
Loading editor...
plaintext