Increasing decreasing sequence

https://hack.codingblocks.com/contests/c/509/194
https://ide.codingblocks.com/#/s/30894
i know my logic is a mess and is wrong on top of that but how can i do it without using arrays(question demands not to use array).

Actually you need not store the numbers, so it can be done without using arrays.
You can check condition while taking input and thus conclude whether it is valid or not.
The sequence can be valid even in the corner cases when the sequence is either completely increasing or completely decreasing also…

i tried a lot but not getting there,can u plz check my code and tell the suggestions!!

You can check this:
https://ide.codingblocks.com/s/47019

this solution is exceeding time for some input, how time can be minimized?