LUCKYNUMS - Editorial

PROBLEM LINK:

Practice

Author: Kunal Demla
Editorialist: Kunal Demla

DIFFICULTY:

cakewalk

PREREQUISITES:

Maths?

SOLUTIONS:

Setters' Solution
#include<bits/stdc++.h>
using namespace std;
#define ll long long int


void solve()
{
    ll n,m,x,y,i,j,k,q;
    cin>>n;
    vector<int> v(n);
    for(i=0;i<n;i++)
        cin>>v[i];
    map<int,int> mp;
        for(auto a:v)
            mp[a]++;
        int ans=-1;
        for(auto m:mp)
            if(m.first==m.second && m.first>ans)
                ans=m.first;
        cout<< ans;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif

int t=1;
// cout<<t<<endl;
// ${2:is Single Test case?}cin>>t;
cin>>t;
int n=t;
while(t--)
{
    //cout<<"Case #"<<n-t<<": ";
    solve();
    cout<<"\n";
}

cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}