Doubt regarding time limit n wrong answer, pls tell me the pseudocode and the working as well

#include
using namespace std;
int main()
{
int n1, n2, n;
bool flag1, flag2;
flag1 = flag2 = 0;
cin >> n;
cin >> n1;
int i = 0;
while (i < n-1)
{
cin >> n2;
if (n2 > n1)
{
flag1 = 1;
n1 = n2;
i++;
}
else if (n1 > n2)
{
flag2 = 1;
n1 = n2;
i++;
}

}
if (flag1 ^ flag2)
{
    cout << "true";
}
else
    cout << "false";

return 0;

}

Quesiton
sequence should be either completely inc or completely decreasing or first dec then inc

Logic
so you have to make sure that once sequence is inc it should not dec in future

Reference Code

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.