Temperature Swing

Easy · rating 900 · arrays

A weather station logged n temperature readings. The first line contains n. The second line contains n integers. Print the difference between the highest and lowest reading.

Editorial

Temperature Swing reports the spread between the hottest and coldest reading — the maximum minus the minimum. A single pass can track both extremes at once.

print(max(temps) - min(temps))

Complexity

Time: O(n). Space: O(1).

Open Temperature Swing in Code Arena →