-
Notifications
You must be signed in to change notification settings - Fork 22
/
Type of array
57 lines (49 loc) · 1.42 KB
/
Type of array
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
/*
You are given an array of size N having no duplicate elements. The array can be categorized into following:
1. Ascending
2. Descending
3. Descending Rotated
4. Ascending Rotated
Your task is to print which type of array it is and the maximum element of that array.
Input:
The first line of input contains an integer T denoting the no test cases. Then T test caes follow. Each testcase contains two lines of input.
The first line contains an integer N denoting the size of the array. The next line contains N space separated values of the array.
Output:
For each test case, print the largest element in the array and and integer x denoting the type of the array.
Constraints:
1 <= T <= 100
3 <= N <= 107
1 <= A[] <= 1018
Example:
Input:
2
5
2 1 5 4 3
5
3 4 5 1 2
Output:
5 3
5 4
Explanation:
Testcase1:
Input : A[] = { 2, 1, 5, 4, 3}
Output : Descending rotated with maximum element 5
Testcase2:
Input : A[] = { 3, 4, 5, 1, 2}
Output : Ascending rotated with maximum element 5*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin>>t; while(t--)
{
int n; cin>>n;
int a[n],i; for(i=0;i<n;i++) cin>>a[i];
int min=*min_element(a,a+n);
int max=*max_element(a,a+n);
if(a[0]==min && a[n-1]==max) cout<<max<<" "<<1<<endl;
else if(a[0]==max && a[n-1]==min) cout<<max<<" "<<2<<endl;
else if(a[1]<a[2] && a[n-1]!=max) cout<<max<<" "<<4<<endl;
else cout<<max<<" "<<3<<endl;
}
return 0;
}