-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIncreasing_Decreasing_sequence.cpp
More file actions
75 lines (63 loc) · 1.42 KB
/
Copy pathIncreasing_Decreasing_sequence.cpp
File metadata and controls
75 lines (63 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*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.*/
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
int left[n];
left[0]=1;
int right[n];
right[n-1]=1;
int c;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=1;i<n;i++)
{
if(arr[i-1]>arr[i])
left[i]=1;
else
left[i]=0;
if(arr[n-i-1]<arr[n-i])
right[n-i-1]=1;
else
right[n-i-1]=0;
}
for(int i=0;i<n-1;i++)
{
if(left[i]+right[i]==0)
{
c=1;
break;
}
else
c=0;
}
if(c==0)
cout<<"true";
else
cout<<"false";
return 0;
}