#include
using namespace std;
int main() {
int n, prev, flag = 0;
cin>> n>>prev;
for (int i = 1; i < n; i++) {
cin>> i;
if (i > prev){
flag = 1;
}
if (flag == 1 && i < prev)
flag = 0;
prev = i;
}
if (flag == 1)
cout<<“true”;
else
cout<<“false”;
return 0;
}
my code for increasing decreasing sequence problem
I didn't understood where my code has gone wrong
#include using namespace std; int main() { int n, prev, flag = 0, i, a = 0; cin>> n>>prev; for (int j = 1; j < n; j++) { a = 1; cin>> i; if (i > prev){ flag = 1; } else if (flag == 1 && i < prev) flag = 0; prev = i; } if (flag == 1 || a == 0) cout<<“true”; else cout<<“false”; return 0; }
@coe17b030
Your code for testcases like this .
Input :
9
3 2 1 2 3 2 1 2 3
Expected Output :
false
Your Output :
true
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.