← Back

Problem 1.2 Cumulative Temperatures

As a data analyst for an environmental research company, you need to identify periods of high temperatures from sensor data collected over time. Your task is to find the contiguous stretch of recorded temperature values that has the highest cumulative temperature. The data includes both positive and negative values, indicating hot and cold tempteratures respectively. By identifying the period with the maximum sum overall, you will be highlighting a stretch of overall warm weather for further analysis of temperature fluctuations.

The problem, then, is this: Given a sequence of temperature readings, determine the start and end indices (which represent start and end time values) of the period that yields the maximum cumulative termperature, as well as report the maximum cumulative value itself.

Examples of inputs and outputs:

Some example inputs and their corresponding outputs are shown below, first in textual and then visual format.

Fiigure 1 below shows the maximum culmulative tempertature segments for the above examples in red

Figure 1: Visual representation of max cumulative temperature segments (in red). As you can see, the max cummulative segments can contain negative values.

Python code

Implement the following function stub:


                

Use the following main to test your function: