Problem: Given an array of integers, count the number of unique values.
For example, if we have the following array:
[1, 1, 1, 1, 1, 1...
For further actions, you may consider blocking this person and/or reporting abuse
One clever solution is to use Set as they have unique values by design:
It's not really an algorithm, tho ;)
... and a lazy solution would be to use underscorejs:
Right... I always forget about sets!
That makes everything so much easier.
My code wouldn't have been that concise but exact solution I thought of
I think also you could use this technique I wrote in this post: dev.to/adtm/whats-your-favorite-al... :)
negating numbers on the fly and checking if they exist, if it doesn't - add +1 to the counter.
What happens when the array isn't pre-sorted?
If it's not pre-sorted you have to use a different approach - the multiple pointers approach won't work.