We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 039c679 + 7bb9053 commit 5b06a37Copy full SHA for 5b06a37
C-or-CPP Projects/EqualDifference.cpp
@@ -0,0 +1,39 @@
1
+#include <iostream>
2
+#include<bits/stdc++.h>
3
+using namespace std;
4
+
5
+int main() {
6
+ // your code goes here
7
+ int t;
8
+ cin>>t;
9
+ while(t--)
10
+ {
11
+ int n;
12
+ cin>>n;
13
+ vector<int> a(n);
14
+ unordered_map<int,int> m;
15
+ for(int i=0;i<n; i++)
16
17
+ cin>>a[i];
18
+ m[a[i]]++;
19
+ }
20
+ if(n<=2)
21
22
+ cout<<0<<endl;
23
24
+ else
25
26
+ int maxi = INT_MIN;
27
+ for(auto it = m.begin(); it!= m.end(); it++)
28
29
+ if(it->second> maxi)
30
31
+ maxi= max(maxi,it->second);
32
33
34
+ int ans= min(n-2, n-maxi);
35
+ cout<<ans<<endl;
36
37
38
+ return 0;
39
+}
0 commit comments