Increasing decreasing sequence


how can we reduce the time taken ?

use these observation
a[i]>a[i-1] when sequences is inc it should not decrease after that
a[i]<a[i-1] when sequences is dec it should not increase before