title: Algorithm: String Similarity
body: <p>I am trying to solve this challenge on InterviewStreet: <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4edb8abd7cacd" rel="nofollow">https://www.interviewstreet.com/challenges/dashboard/#problem/4edb8abd7cacd</a></p>
  
  <p>I already have a working algorithm but I would to improve its performance. Do you have any suggestions how to do so?</p>
  
  <pre><code># Enter your code here. Read input from STDIN. Print output to STDOUT
  N = gets.to_i
  words = []
  
  while words.length &lt; N do
    words &lt;&lt; gets.sub(/\\n$/, '').strip
  end 
  
  words.each do |word|
    count = 0
    (word.length).times do |i|
      sub = word[i..-1]
      j=0
      while j &lt; sub.length &amp;&amp; sub[j] == word[j] do
        count += 1 
        j+=1
      end
    end
    puts count
  end
  </code></pre>
  
  <p>Thanks,
  Greg</p>