I have tried this problem multiple times but the problem i am facing is i dont recognize what my solution lacks like in question it is said we can divide sequence in two parts or can there be multiple parts of sequence like two strictly increasing part and three strictly decreasing ones ?
Unsuccessful Test cases
hello @tanishchaurasiacool
no that is not case . all u need to check is whether the given sequence is first decreasing and then increasing or not.
refer this->
First we assume that our sequence is decreasing only. We also assume that our sequence is initially valid and only try to disprove it during the course.
We compare our current element with the previous element and based on that comparison make our decision.
If the curr element is equal to the prev element , we see that the sequence is neither strictly increasing or decreasing so we mark our sequence as invalid.
If the curr element is greater than the prev element, then we realise that the sequence has started increasing and we mark it so using a flag variable “goingUp” which we had initially marked as false based on our assumption that the sequence is decreasing.
If the curr element is less than the previous element and the current sequence is also proceeding as decreasing , we are to do nothing. However if the current sequence is increasing and we get a pair for a decreasing sequence then we mark our sequence as invalid since we cannot have a decreasing part after the increasing sequence.
After each iteration , store the value of the curr element into the prev element so that we cAan compare it with the next input element.
code->