We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1be27c6 + 5b3c800 commit 1a1ba7dCopy full SHA for 1a1ba7d
1 file changed
Problems/Mathematics/Day-02/sol/PrithaJaiswal/solution.cpp
@@ -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