Link Details

Link 875995 thumbnail
User 1073519 avatar

By lokeshgupta1981
Published: Nov 11 2012 / 09:37

This is very common interview question where you have to find duplicate words in a string or some text. This can be solved using some overly-complex algorithms also, but in this post, I will propose rather an easy way using java collections.
  • 3
  • 0
  • 1684
  • 1404
User 272422 avatar

htowninsomniac replied ago:

1 votes Vote down Vote up Reply

As interviewer, my next question would be "great, now assume Collections.frequency didn't exist. How would you do it then?" And strictly speaking, your answer still needs to eliminate words that have frequency 1.

User 1073519 avatar

lokeshgupta1981 replied ago:

1 votes Vote down Vote up Reply

You can ask. You are the boss... Let me make a wild guess. In my other simplest solution, I will sort the collection so that it makes similar words in sequence. Now a simple iteration will filter out all different words and their frequency.. including one also. You can choose them to ignore. I know this solution can have some performance overhead, but for that large load of data, I will go for some expert algorithm implementation. Otherwise, it is also good to go.

Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Upvoters (3)

Downvoters (0)

    Apache Hadoop
    Written by: Piotr Krewski
    Featured Refcardz: Top Refcardz:
    1. Play
    2. Akka
    3. Design Patterns
    4. OO JS
    5. Cont. Delivery
    1. Play
    2. Java Performance
    3. Akka
    4. REST
    5. Java