currently i am doing problem on data structure and i have a question in which i have to find kth largest element in an array. the actual problem is here: https://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array/.
i did this question in two different way using heap and second is using map.
my solution using map.
int t;
cin>>t;
while(--t>=0){
int n,k;
cin>>n;
vector<int> A(n);
for(int i=0;i<n;i++){
cin>>A[i];
}
cin>>k;
map<int,int> m;
for(int i=0;i<n;i++){
m[A[i]]++;
}
auto it=m.begin();
for(int i=1;i<=k-1;i++){
it++;
}
cout<<it->first<<endl;
but my map solution is giving Time Limit Exceeded. according to me map solution also has a time complexity of (n+klog(n)), same as heap solution. so why is map solution giving TLE?