How to find all the characters in a string with an appearance greater than 2

advertisements

I have a question about algorithm:

How to find all characters in a string whose appearance is greater than a specific number, say 2 for example efficiently?

Regards.


Counting sort will be extremely efficient for one-byte encodings, border case is two-byte encodings. For wider encodings it is not so efficient, but counting array may be replaced with hash table.

EDIT: By the way, that is too general solution, doing only counting phase and outputting results on the fly will be more than enough.