30 Days of Code [Day 8]
QUESTION : Equal Difference
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long>
#define vvl vector<vl>
#define pii pair<int, int>
#define pll pair<long, long>
#define endl "\n"
#define fo(i,s,n) for(int i=s;i<n;++i)
#define of(i,s,n) for(int i=s-1;i>=n;--i)
#define printv(v) for(auto &it : v){cout<<it<<" ";}cout<<endl;
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fv(V) for( auto &it : V )
const int MOD = 1e9+7;
void solve()
{
int n;
cin>>n;
vi v(n);
map<int, int>m;
int mx = INT_MIN;
fo(i,0,n){
cin>>v[i];
m[v[i]]++;
mx = max(mx, m[v[i]]);
}
if(n <= 2) cout<<"0"<<endl;
else if(mx == 1) cout<<n-2<<endl;
else cout<<n-mx<<endl;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll T=1;
cin>>T;
while(T--) solve();
return 0;
}