how to make the program strictly increasing or decreasing ?i have passed 4 test cases but 5 test cases goes wrong? how to resolve this problem??
Increasing decreasing sequence
@amishakumari
the approach for solving is pretty simple keep increasing the i till i-1 <= i and when it is voilated keep increasing i till i-1 >= i. It i == n in the end then its increasing decreasing sequence.
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 && curr < prev)
{
isValid = false;
break;
}
prev = curr;
}
return isValid;
}
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.