Here’s the question link : https://cses.fi/problemset/task/1621

Here’s my solution using unordered maps ( I know that sets can be used here but I want to know what’s wrong with my solution, it’s giving TLE in few testcases where n=1e5 and answer should be also 1e5 ) : https://cses.fi/problemset/result/2310768/

I am not able to see the solution.

Code is not visible with that link

Your solution is not visible. There’s no need to use set or map just sort array and check for a[i]!=a[i-1]. Here’s sample code:

vi v;input(v,n); sort(v.begin(),v.end()); ll ans = 0,prev = -1; for(auto i:v){ if(i!=prev){ prev = i; ans++; } } cout<<ans;