Tuesday, January 4, 2011

Find Top N

I am putting a problem here that I am currently working on:

You are given a list of S strings. Find the top N strings with the highest occurrence count from this list.

e.g. Let the list of strings be [ "xyz", "pqr", "abc", "xyz", "abc", "xyz", "lmn" ]
The top 2 strings are ["xyz" # 3, "abc" # 2] where number after the hash gives the count of occurrence.

I am working on the problem in server-side JavaScript that is used in XPages technology in IBM Lotus Domino. I already have found two solutions which I will discuss in next posts.

Updated: Solution 1, Solution 2 and Solution 3 (the optimal) are available.

No comments:

Post a Comment