Sir, does this code not work in O(n) time?

#include
#include
using namespace std;
int main() {
int n;
pair<int,int>p;
p.first=0;
map<int,int>m;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
m[a[i]]++;
if(m[a[i]]>p.first)
{
p.first=m[a[i]];
p.second=a[i];
}
}
cout<<p.second;
return 0;
}

@kodivine0, the time complexity of your code is o(nlogn) as you are using map, and insertion and access takes o(logn) time in map, so use unordered_map as its time complexity for access and insertion is o(1)

corrected code :- https://ide.codingblocks.com/s/327113

In case of any doubt feel free to ask :slight_smile:
Mark your doubt as RESOLVED if you got the answer