Https://hack.codingblocks.com/contests/c/509/194

https://hack.codingblocks.com/contests/c/509/194

Here’s my code:

#include
#include
using namespace std;
int main(){
long n,x=0,toggle;
cin>>n;
long a[n];
for(int i=0;i<n;i++){
cin>>a[n];
}
for(int i=0;i<n-1;i++){
if(a[i]<a[i+1]){
toggle=i;
x++;
break;
}
}
for(int i=toggle+1;i<n-1;i++){
if(a[i]>a[i+1]){
x++;
break;
}
}
if(x==1){
cout<<“true”;
}
else{
cout<<“false”;
}
return 0;
}

Please help me find where I went wrong.

Actually you are missing out the border cases. The sequence would be valid even when it is completely increasing or completely decreasing. Try again with this approach.

1 Like