Code Logo

Find Warmest Temperature

Published at19 Apr 2026
Easy 0 views
Like0

This problem feels like checking a simple weather report. You have a list of temperatures, and you want to know which one was the warmest.

The answer is the largest number in the list. You do not need to sort everything or keep every result. You only need to remember the highest temperature seen so far.

For example, if the readings are [28, 31, 26, 33, 30], the answer is 33. Even though the temperatures go up and down, 33 is the highest value in the whole list.

If the list is empty, return -1 because there is no temperature to report.

Example Input & Output

Example 1
Input
temps = [28, 31, 26, 33, 30]
Output
33
Explanation

33 is the highest reading in the list.

Example 2
Input
temps = [15]
Output
15
Explanation

With one reading, that value is automatically the warmest.

Example 3
Input
temps = []
Output
-1
Explanation

An empty list has no valid temperature to return.

Algorithm Flow

Recommendation Algorithm Flow for Find Warmest Temperature
Recommendation Algorithm Flow for Find Warmest Temperature

Solution Approach

A good way to solve this is to keep track of the largest value while moving through the list.

First, handle the empty-list case. If there are no readings, return -1 right away.

If the list has values, start by storing the first temperature in a variable like warmest. That gives you a starting answer to compare against.

Then go through the rest of the readings one by one. Each time, compare the current reading with warmest.

The update step is:

if temps[i] > warmest then warmest <- temps[i] endif

If the current reading is higher, replace the old saved value. If it is not higher, keep the old one.

By the time the loop ends, warmest holds the largest temperature in the list.

Best Answers

Solutions Coming Soon

Verified best solutions for this Challenge are still being analyzed and will be available soon.