Highest Frequency (Hashing)

2 out of 4 test cases are failing (TLE)

#include<iostream>
#include<unordered_map>
using namespace std;

int arr[10000000];
int main(){

    int n;
	cin>>n;

	int cnt = 0;
	int ans = -1;

	unordered_map<int,int> h;
	for(int i=0; i<n; i++){
		h[i] = 0;
	}

	for(int i=0; i<n; i++){
		cin>>arr[i];
		h[arr[i]]++;
		if(cnt < h[arr[i]]){
			cnt = h[arr[i]];
			ans = arr[i];
		}
	}

	cout<<ans<<endl;
    return 0;
}
for(int i=0; i<n; i++){
	h[i] = 0;
}

what do u mean by doing this???
unnecessarily making things complicated… refer my code https://ide.codingblocks.com/s/623711

initialising elements of map with 0. Is this not needed?
p.s. i am a beginner, so i need to get things very clear, even if it makes things complicated.

no this is not needed… nothing to worry with practice you would get hold of things…
if still there is any doubt do let me know…

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.