Sir,test case 1 & 2 fail .where i am wrong

#include
#include<bits/stdc++.h>
using namespace std;

int main() {
int n;
cin>>n;
int a[n];
int j=0;

unordered_map<int,int>mp;

for(int i=0;i<n;i++){
cin>>a[i];
mp[a[i]]++;
}
int max=0;
int ans;
for(auto it:mp){
if(it.second>max){
max=it.second;
ans=it.first;
}
}

cout<<ans;
return 0;
}

@dineshjani
hello dinesh,
if there are more than one character with maximum frequency then print smallest character among them.

for example if a and b have maximum frequency then print a

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.