Test case working but other cases not working.
Code not working
@siddhu28.ss
You have consider only strictly increasing or decreasing subarray. But you have to include equal elements too in your final ans.
Consider this testcase
1
7
1 3 2 2 4 5 6
output should be 5 (2 2 4 5 6 subarray)
#include<bits/stdc++.h>
using namespace std;
int main() {
int t; cin >> t;
while(t > 0){
int n; cin >> n;
int arr[n];
for(int i = 0; i < n; i++)
cin >> arr[i];
int max_length = 1;
int curr_length = 1;
int i =1;
bool decreasing = false;
while(i < n){
if(arr[i] == arr[i-1]){
curr_length++;
if(max_length < curr_length)
max_length = curr_length;
if(decreasing && i != n-1 && arr[i] < arr[i+1]){
curr_length = 2;
decreasing = false;
}
}
if(arr[i] > arr[i-1]){
decreasing = false;
curr_length++;
if(max_length <curr_length)
max_length = curr_length;
}
else if(arr[i] < arr[i-1]){
decreasing = true;
curr_length++;
if(max_length < curr_length)
max_length = curr_length;
if(i != n-1 && arr[i+1] > arr[i])
curr_length = 1;
}
i++;
}
cout<<max_length<<endl;
t--;
}
return 0;
}
handled the equality clause, any other issue( test case 2 and 3 are not working, 1 started working)