Here’s the question link :
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 ) :
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:
ll ans = 0,prev = -1;
prev = i;