Trains the technique from
LeetCode 643Maximum Average Subarray IThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A weather station keeps one figure per day for a site: the daily anomaly, how far that day sat above or below the long-run norm, measured in tenths of a degree. A cold day carries a negative figure.
You are given the array anomalies, one figure per day in date order, and an integer span. Look at every block of span days that run back to back, work out the mean anomaly of each block as the block total divided by span, and report the largest mean any block reaches.
Return the mean as a real number; a reported figure off by less than 1e-5 from the true one is accepted. Since span never exceeds the number of days on record, at least one block always exists.
Example 1
The four blocks total 13, 8, 15 and 19. The last three days total 19, the largest of them, so the mean reported is 19 divided by 3.
Example 2
Only one block of two days exists and both days ran cold, so the reported mean is negative.
Example 3
A single day forms the only block, and a block of one day has that day's figure as its mean.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def warmest_run_average(anomalies: list[int], span: int) -> float:public double warmestRunAverage(int[] anomalies, int span)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.