File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-02/BEESA_MANISH Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ /*
3+ TC -O(N)
4+ SC-O(N)
5+ */
6+
7+ #include < iostream>
8+ #include < vector>
9+ #include < algorithm>
10+
11+ using namespace std ;
12+
13+ void solve () {
14+ int n;
15+ cin >> n;
16+ vector<int > a (n);
17+ int min_val = 1e9 , max_val = -1e9 ;
18+ for (int i = 0 ; i < n; i++) {
19+ cin >> a[i];
20+ if (a[i] < min_val) min_val = a[i];
21+ if (a[i] > max_val) max_val = a[i];
22+ }
23+ if (min_val == max_val) {
24+ cout << 1LL * n * (n - 1 ) << endl;
25+ return ;
26+ }
27+ long long count_min = 0 ;
28+ long long count_max = 0 ;
29+ for (int i = 0 ; i < n; i++) {
30+ if (a[i] == min_val) count_min++;
31+ if (a[i] == max_val) count_max++;
32+ }
33+ cout << 2 * count_min * count_max << endl;
34+ }
35+ int main () {
36+ int t;
37+ cin >> t;
38+ while (t--) {
39+ solve ();
40+ }
41+ return 0 ;
42+ }
You can’t perform that action at this time.
0 commit comments