Skip to content

Commit a53145e

Browse files
DAY 2 Q 1 Solved
1 parent f9e5887 commit a53145e

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

  • Problems/Mathematics/Day-02/sol/Aiyaan_Mahajan
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Q1 Hossam and Combinatorics
3+
.*/
4+
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
8+
void solve() {
9+
int n;
10+
cin >> n;
11+
12+
vector<int> a(n);
13+
for (int i = 0; i < n; i++) {
14+
cin >> a[i];
15+
}
16+
17+
int minVal = *min_element(a.begin(), a.end());
18+
int maxVal = *max_element(a.begin(), a.end());
19+
20+
if (minVal == maxVal) {
21+
long long ans = (long long)n * (n - 1);
22+
cout << ans << "\n";
23+
return;
24+
}
25+
26+
long long minCount = count(a.begin(), a.end(), minVal);
27+
long long maxCount = count(a.begin(), a.end(), maxVal);
28+
29+
long long ans = 2 * minCount * maxCount;
30+
cout << ans << "\n";
31+
}
32+
33+
int main() {
34+
int t;
35+
cin >> t;
36+
37+
while (t--) {
38+
solve();
39+
}
40+
41+
return 0;
42+
}
43+
44+
45+
//Time Complexity: O(n)
46+
//Space Complexity: O(n)
47+
/*
48+
My submission : https://codeforces.com/contest/1771/submission/355468439
49+
*/

0 commit comments

Comments
 (0)