/*
* @lc app=leetcode id=978 lang=cpp
*
* [978] Longest Turbulent Subarray
*/
// @lc code=start
class Solution {
public:
int maxTurbulenceSize(vector<int>& arr) {
int N = arr.size();
if(N<=1){
return N;
}
int up = 1, down = 1;
int ans = 1;
for(int i=1;i<N;i++){
if(arr[i] > arr[i-1]){
up = down + 1;
down = 1;
}else if(arr[i] < arr[i-1]){
down = up + 1;
up = 1;
}else{
up = down = 1;
}
ans = max(ans, max(up, down));
}
return ans;
}
};
// @lc code=end