Why i am getting wrong answer in increasing decreasing sequence

#include
using namespace std;

bool increasingDecreasing(int n)
{
int prev;
cin >> prev;

bool isValid = true;
bool isDecreasing = true;

while (--n)
{
    int curr;
    cin >> curr;
    if (curr == prev)
    {
        isValid = false;
        break;
    }
    else if (curr > prev)
    {
        isDecreasing = false;
    }
    else if (isDecreasing!=false && curr < prev)
    {
        isValid = false;
        break;
    }

    prev = curr;
}

return isValid;

}

int main()
{
int n;
cin>>n;
if(increasingDecreasing(n))
{
cout<<“true”;
}
else
{
cout<<“false”;
}
return 0;
}

Hi @sroy3166,
first, since u r breaking ur while loop in between , u r ignoring someinputs which are being given by the grader.
so add
if(n>0){
while(–n){
int curr;
cin >> curr;
}
}
after the present while loop in ur code function.
2) ur code outputs true when input = {1,2,3,2,1}. whereas output should be false.
try modifying ur code.
Hope dis helps.
If u still have any doubts or feel like something is unclear, feel free to post ur doubts here.

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.