Skip to content

Instantly share code, notes, and snippets.

View nishchayksharma's full-sized avatar

Nishchay Sharma nishchayksharma

View GitHub Profile
@nishchayksharma
nishchayksharma / stringsim
Created December 12, 2011 11:15
String Similarity Problem
String Similarity (25 Points)
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.
Input:
The first line contains the number of test cases T. Each of the next T lines contains a string each.
Output:
Output T lines containing the answer for the corresponding test case.
Constraints:
1 <= T <= 10
The length of each string is at most 100000 and contains only lower case characters.