File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-02/sol/Aiyaan_Mahajan Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ */
You can’t perform that action at this time.
0 commit comments