Check Number sequence
Check Number sequence
Send Feedback
Check Number sequence
Line 1 : Integer 'n'
Line 2 and Onwards : 'n' integers on 'n' lines(single integer on each line)
"true" or "false" (without quotes)
1 <= n <= 10^7
5
9
8
4
5
6
true
3
1
2
3
true
3
8
7
7
false
8 7 7 is not strictly decreasing, so output is false.
6
8
7
6
5
8
2
false
The series is :
8 7 6 5 8 2
It is strictly decreasing first (8 7 6 5). Then it's strictly increasing (5 8). But then it starts strictly decreasing again (8 2). Therefore, the output for this test case is 'false'
#include<iostream>using namespace std;
// int main() {// // Write your code here// int n;// cin>>n;// int array[n];// for(int i=0;n>i;i++){// cinarray[i];// }// int j=i+1;// for(int i=0;n>i;i++){// if(j>i){// return // }// }// }// int main() {// int n;// cin >> n;// int prev;// cin >> prev;// int count = 2, current;// bool isDec = true;// while(count <= n) {// cin >> current;// if(current == prev) {// cout << "false";// return 0;// }// count++;// if(current < prev) {// if(isDec == false) {// cout << "false";// return 0;// }// }// else {// if(isDec == true) {// isDec = false;// }// }// prev = current;// }// cout << "true";// }
int main(){ int n; cin>>n; int previous,current,i=1; cin>>previous; bool isdec=true; while(n>i){ cin>>current; if(previous==current){ cout<<"false"; return 0; //this function will end here } if(previous<current){ isdec=false; } if(previous>current){ if(isdec==false){ cout<<"false"; return 0; } } i++; previous=current; } cout<<"true";}
Comments
Post a Comment