Not able to figure out error

#include
using namespace std;

int main()
{
int T;
cin>>T;

if(T>=1 && T<=100){
for (int TestCase = 0; TestCase < T; TestCase++)
{

int N,max;
cin>>N;

int Array[N];
int Inc[N] ={0};
int Dec[N] ={0};
Inc[0]=1;
Dec[N-1]=1;

for (int i = 0; i < N; i++)
{
    cin>>Array[i];
}

for (int i = 1; i < N; i++)
{
    if (Array[i]>Array[i-1])
    {
        Inc[i]= Inc[i-1]+1;
    }
    else
    {
        Inc[i]=1;
    } 
}

for (int i = N-2; i >=0; i--)
{
    if (Array[i]>Array[i+1])
    {
        Dec[i]= Dec[i+1]+1;
    }
    else
    {
        Inc[i]=1;
    } 
}
max =Inc[0]+Dec[0]-1;

for (int i = 0; i <N; i++)
{
    if (Inc[i]+Dec[i]-1>max)
    {
        max=Inc[i]+Dec[i]-1;
    }
    
}
cout<<max<<endl;
}
}

}

(Array[i] >= Array[i-1]) here

(Array[i] >= Array[i+1]) here

Rest looks good
If this resolves your query then please hit a like :slight_smile:

not able to find error in this

if consecutive elements are same then also we can say its increasing or decreasing
Say
1 1 1
So here increasing array should be
1 2 3 instead of
1 1 1
Similarly for decreasing array

I did it but there is also some which is not figure out…

#include using namespace std; int main() { int T; cin>>T; if(T>=1 && T<=100){ for (int TestCase = 0; TestCase < T; TestCase++) { int N,max; cin>>N; int Array[N]; int Inc[N] ={0}; int Dec[N] ={0}; Inc[0]=1; Dec[N-1]=1; for (int i = 0; i < N; i++) { cin>>Array[i]; } for (int i = 1; i < N; i++) { if (Array[i]>Array[i-1]) { Inc[i]= Inc[i-1]+1; } else { Inc[i]=1; } } for (int i = N-2; i >=0; i–) { if (Array[i]>Array[i+1]) { Dec[i]= Dec[i+1]+1; } else { Inc[i]=1; } } max =Inc[0]+Dec[0]-1; for (int i = 0; i <N; i++) { if (Inc[i]+Dec[i]-1>max) { max=Inc[i]+Dec[i]-1; } } cout<<max<<endl; } } }

#include
using namespace std;

int main()
{
int T;
cin>>T;

if(T>=1 && T<=100){
for (int TestCase = 0; TestCase < T; TestCase++)
{

int N,max;
cin>>N;

int Array[N];
int Inc[N] ={0};
int Dec[N] ={0};
Inc[0]=1;
Dec[N-1]=1;

for (int i = 0; i < N; i++)
{
    cin>>Array[i];
}

for (int i = 1; i < N; i++)
{
    if (Array[i]>=Array[i-1])
    {
        Inc[i]= Inc[i-1]+1;
    }
    else
    {
        Inc[i]=1;
    } 
}

for (int i = N-2; i >=0; i--)
{
    if (Array[i]>=Array[i+1])
    {
        Dec[i]= Dec[i+1]+1;
    }
    else
    {
        Inc[i]=1;
    } 
}
max =Inc[0]+Dec[0]-1;

for (int i = 0; i <N; i++)
{
    if (Inc[i]+Dec[i]-1>max)
    {
        max=Inc[i]+Dec[i]-1;
    }
    
}
cout<<max<<endl;
}
}

}

This one should be dec[i]=1

thanks … .

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.