Longest heatwave streak
A city council defines a heatwave as consecutive days hotter than a chosen temperature and needs the longest one to plan cooling centres. Data: weather.csv, covering 45 days from 2025-07-01 for six cities.
date: YYYY-MM-DDcity: city nametemp_c: average temperature in Celsiusrain_mm: rainfall in mm
Every city has exactly one row per day and its rows are in date order. Task: the first input line is a city, the second a temperature threshold. A day is hot when temp_c is strictly greater than the threshold. Print Longest streak: N days where N is the longest run of consecutive hot days of that city. If N is above 0, print a second line From D1 to D2 with the first and last date of the earliest streak that has length N. Unknown city: Longest streak: 0 days only.
Files your program can read
date,city,temp_c,rain_mm 2025-07-01,Lisbon,21.4,0.0 2025-07-01,Nairobi,22.6,0.0 2025-07-01,Mumbai,29.1,0.0 2025-07-01,Toronto,21.0,0.0 2025-07-01,Sydney,14.8,0.0 2025-07-01,Reykjavik,7.9,0.0 2025-07-02,Lisbon,21.1,0.0 ...
Open them by name, for example open("weather.csv").
Sample test
Input
Lisbon 24
Expected output
Longest streak: 16 days From 2025-07-07 to 2025-07-22
Your answer is also checked against 5 hidden tests.
Need a hint?
Keep a counter of the current streak and reset it to zero on the first day that is not hot.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
