A freezer in a cold-storage warehouse has a sensor that records its temperature once every minute. The readings are stored in time order.
A steady stretch is a group of back-to-back minutes that all have the same temperature. Only neighbouring minutes count, so if a reading comes back after a different reading, it starts a new stretch.
Return the number of minutes in the longest steady stretch. If there are no readings, return 0.
int longestSteadyStretch(List<Integer> temperatures)
temperatures.get(i) is the temperature at minute i.0 ≤ temperatures.size() ≤ 100,000-500 ≤ temperatures.get(i) ≤ 1000longestSteadyStretch(temperatures = [-12, -12, -10, -10, -10, -10, -12])
Output: 4
The steady stretches are [-12, -12], [-10, -10, -10, -10] and [-12]. The longest one is -10 for 4 minutes.
longestSteadyStretch(temperatures = [-25, -25, -25])
Output: 3
The temperature never changes, so all 3 minutes form one stretch.
longestSteadyStretch(temperatures = [-8, -9, -8])
Output: 1
No two neighbouring minutes have the same temperature, so every stretch lasts 1 minute.
longestSteadyStretch(temperatures = [-14, -14, -16, -14, -14, -14])
Output: 3
-14 appears 5 times, but -16 splits it into two stretches of 2 and 3 minutes. The longer one has 3 minutes.
longestSteadyStretch(temperatures = [])
Output: 0
There are no readings, so the answer is 0.