Increasing decreasing sequence

Given an array S of size N , check if it is possible to split sequence into two sequences -
s1 to si and si+1 to sN such that first sequence is strictly decreasing and second is strictly increasing. Print true/false as output.

Input Format
First line contains a single integer N denoting the size of the input.
Next N lines contain a single integer each denoting the elements of the array S.

Constraints
0 < N < 1000 Each number in sequence S is > 0 and < 1000000000

Output Format
Print boolean output - “true” or “false” defining whether the sequence is increasing - decreasing or not.

Sample Input
5
1
2
3
4
5
Sample Output
true
Explanation
Carefully read the conditions to judge which all sequences may be valid. Don’t use arrays or lists.

"i am not able to understand the sample input output according to the problem statement…sample output should be false here…as there is only increasing sequence and not decreasing.

Hey @srishti200201_c9588863a697e1e7,

Following are the possible cases for this question.

  • A sequence is true if you can split it into two sub sequence such that first sequence is strictly increasing and second sequence is strictly decreasing.
  • For e.g.,
    1 2 3 4 5
    This sequence is also true as we can split it into two sequence like., sequence one is empty and sequence two is 1 2 3 4 5.
  • Let’s take another example.,
    5 4 3 2 1
    This is also true as we can split it such that sequence one is 5 4 3 2 1 and sequence two is empty.

According to the problem statement, we can say the if the sequence decreases then it should not increase, if this is the case one can directly print false.

  • The third case is when the sequence is first strictly decreasing then strictly increasing.
    For example :
    9 5 2 7 10
    The sequence first decreases starting from 9 to 2 - { 9, 5, 2 } and then starts increasing - { 7, 10}. Note that it can also be broken as { 9, 5} and { 2, 7, 10} . Since the sequence fulfills the required condition , we would also print “true” for this.
  • If a sequence does not meet any of the above criteria , we return “false” for it.

Hope it helps :slight_smile:

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.

My code satisfy all your condition but still i got some test cases failed.