Problem 191210 · medium · Phase 01 Prerequisites & Setup

Longest Heatwave

loops · lists · counting · running maximum

A heatwave is a run of consecutive days whose temperature is at least threshold. Write longest_heatwave(temps, threshold) that returns the length of the longest heatwave in the list temps. Return 0 if no day reaches the threshold.

Examples

Input:  temps = [30, 32, 28, 31, 33, 35], threshold = 30
Output: 3
Explanation: days 31, 33, 35 form a run of three.

Input:  temps = [], threshold = 30
Output: 0

Constraints

  • 0 <= len(temps) <= 10**5
  • -100 <= temps[i], threshold <= 100

Goals

  • Count the length of the current run while looping
  • Reset the run counter when the condition fails and keep the best run
Starting Python…