#include
#include <unordered_map>
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
unordered_map<int,int> hash;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
hash[a[i]]++;
int res=0;
int max=0;
for(auto i:hash)
{
if(max<i.second)
{
max=i.second;
res=i.first;
}
}
cout<<res;
return 0;
}
Tow test cases not satisfying
@ArshjitSingh Initialize max with INT_MIN and then check. You code will fail when there are negative numbers in the input.
Try to correct yourself. If still test cases do not pass then please save your code on ide.codingblocks.com and share its link.
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.