Skip to content

Commit 0ca8530

Browse files
authored
Merge pull request #289 from d2-e2-v2/main
added solution for Day 2 q1
2 parents 7517f24 + 2e5d044 commit 0ca8530

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
The problem relies permutations between the max and min elements, and a (i,j) and(j,i) being unique.
3+
The special case is when the entire array is the same. then we simply needed to use nC2*2!.
4+
5+
Time complexity- O(nlogn)
6+
Sorting is not needed, but makes implementaion easier.
7+
Submission link- https://codeforces.com/contest/1771/submission/355301277
8+
*/
9+
#include <bits/stdc++.h>
10+
using namespace std;
11+
int main() {
12+
ios::sync_with_stdio(false);
13+
cin.tie(nullptr);
14+
int t;
15+
cin >> t;
16+
17+
while (t--) {
18+
int n;
19+
cin>>n;
20+
vector<int>arr(n);
21+
for(int i=0;i<n;i++)
22+
{
23+
cin>>arr[i];
24+
}
25+
sort(arr.begin(),arr.end());
26+
long long mincount=0;
27+
long long maxcount=0;
28+
for(int i=0;i<n;i++)
29+
{
30+
if(arr[i]==arr[0])
31+
mincount++;
32+
if(arr[i]==arr[n-1])
33+
maxcount++;
34+
}
35+
long long a;
36+
a=2LL*mincount*maxcount;
37+
if(arr[0]==arr[n-1])
38+
{ a=1LL*(n-1)*(n);
39+
40+
41+
cout<<a<<endl;
42+
}
43+
else
44+
cout<<a<<endl;
45+
}
46+
return 0;
47+
}
48+

0 commit comments

Comments
 (0)