For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3.
Calculate the sum of similarities of a string S with each of it's suffixes.
instead of creating multiple substrings, create a virtual substring inline. Read full article from Break the CODE!!!: Interviewstreet Challenge: String Similarityprivate static int getcount( char[] s ) {int i = 0;int n = s.length;int total = 0;while( i < n ) {int sum = 0;int k = 0;while( i+k < n ) {if(s[k] == s[i+k] ) {sum++;} else {break;}k++;}total += sum;i++;}return total;}