i am getting wrong answer on test case 3 and 7. i have checked each and everything. Please let me know if i am missing something,
Here is my code:
#include
using namespace std;
int main() {
int n,a,b,count=1,diff;
bool flag=true,increasing=false;
cin>>n;
cin>>a;
while(count<n){
cin>>b;
diff=b-a;
if(diff==0)
flag=false;
else if(diff>0)
increasing=true;
else if(diff<0 && increasing)
flag=false;
b=a;
count++;
}
if(flag)
cout<<“true”<<endl;
else
cout<<“false”<<endl;
return 0;
}
Testcase 3 and 7 not working
Hi, your code is not working correctly for the case when the sequence is first decreasing and then increasing.
For example, for the case when:
Input:
5
5 4 3 4 5
Expected output is true as first the sequence is strictly decreasing and then strictly increasing, but your code prints false in this case.
Hi, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.