Link Details

Link 875995 thumbnail
User 1073519 avatar

By lokeshgupta1981
via howtodoinjava.com
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
  • 1433
  • 1384

Comments

Add your comment
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.

Voters For This Link (3)



Voters Against This Link (0)



    Spring Integration
    Written by: Soby Chacko
    Featured Refcardz: Top Refcardz:
    1. Search Patterns
    2. Python
    3. C++
    4. Design Patterns
    5. OO JS
    1. PhoneGap
    2. Spring Integration
    3. Regex
    4. Git
    5. Java