BackmediumArrays Paytm

Temperature Fluctuation Analysis Solution

Problem Statement

Given an array of daily temperature fluctuations, find the minimum length of a subarray that contains alternating increases and decreases in temperature.

Example 1
Input
[20, 15, 30, 25, 10]
Output
5

Explanation: Step-by-step: Given the array [20, 15, 30, 25, 10], we can see that the subarray [20, 15, 30, 25, 10] has alternating increases and decreases in temperature. The minimum length of this subarray is 5.

Example 2
Input
[10, 20, 15, 30, 25, 10, 35]
Output
7

Explanation: Step-by-step: Given the array [10, 20, 15, 30, 25, 10, 35], we can see that the subarray [10, 20, 15, 30, 25, 10, 35] has alternating increases and decreases in temperature. The minimum length of this subarray is 7.

Constraints

  • 1 <= array length <= 10^5
  • All elements are distinct integers in the range [-10^9, 10^9].
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free