Rising Temperature

easy hash map database date diff

Problem

Find all dates' Ids in Weather whose temperature is higher than the previous day's temperature.

SQL: SELECT w1.id FROM Weather w1 JOIN Weather w2 ON DATEDIFF(w1.recordDate, w2.recordDate) = 1 WHERE w1.temperature > w2.temperature;

InputWeather = [(1, 2015-01-01, 10), (2, 2015-01-02, 25), (3, 2015-01-03, 20), (4, 2015-01-04, 30)]
Output[2, 4]

SELECT w1.id FROM Weather w1 JOIN Weather w2
  ON DATEDIFF(w1.recordDate, w2.recordDate) = 1
WHERE w1.temperature > w2.temperature;
Time: O(n) Space: O(n)