Skip to content

Commit 5b3c800

Browse files
committed
solution to day 2 problem 1
1 parent 85c8ff6 commit 5b3c800

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main(int argc, char const *argv[])
5+
{
6+
int t;
7+
cin >> t;
8+
while (t--)
9+
{
10+
long long int n;
11+
cin >> n;
12+
vector<long long int> arr(n);
13+
14+
for (int i = 0; i < n; i++)
15+
{
16+
cin >> arr[i];
17+
}
18+
19+
sort(arr.begin(), arr.end());
20+
int min_val = arr[0];
21+
int max_val = arr[n - 1];
22+
23+
long long int count_min = 0, count_max = 0;
24+
for (long long int i = 0; i < n; i++)
25+
{
26+
if (arr[i] == min_val)
27+
{
28+
count_min++;
29+
}
30+
else if (arr[i] == max_val)
31+
{
32+
count_max++;
33+
}
34+
}
35+
36+
if (min_val == max_val)
37+
{
38+
cout << n * (n - 1) << endl;
39+
continue;
40+
}
41+
42+
cout << 2LL * count_min * count_max << endl;
43+
}
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)