forked from kirito-udit/DSA-450
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinMaxArray.cpp
48 lines (44 loc) · 840 Bytes
/
MinMaxArray.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,i;
cin>>n;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
int min,max;
if(a[0]>a[1])
{
min=a[1];
max=a[0];
}
else
{
min=a[0];
max=a[1];
}
for(i=2;i<n-1;i+=2)
{
if(a[i]<a[i+1])
{
if(a[i]<min) min=a[i];
if(a[i+1]>max) max=a[i+1];
}
else
{
if(a[i]>max) max=a[i];
if(a[i+1]<min) min=a[i+1];
}
}
cout<<"Minimum is "<< min << endl;
cout<<"Maximum is "<< max << endl;
}
return 0;
}