6 kyu

String Suffixes

536 of 1,265debri

Description:

Let's say take 2 strings, A and B, and 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.

write a function that calculates the sum of similarities of a string S with each of it's suffixes.

Examples (input -> output):

'ababaa' -> 11
'abc' -> 3

Explanation:

In the first case, the suffixes of the string are ababaa, babaa, abaa, baa, aa and a. The similarities of each of these strings with the string ababaa are 6,0,3,0,1,1 respectively. Thus the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11.

For the second case, the answer is simply 3 + 0 + 0 = 3.

Note : Each string will have at least one character - no need to check for empty strings :)

Strings
Logic
Arrays
Algorithms

More By Author:

Check out these other kata created by debri

Stats:

CreatedJul 8, 2015
PublishedJul 8, 2015
Warriors Trained2344
Total Skips113
Total Code Submissions3675
Total Times Completed1265
JavaScript Completions513
Ruby Completions101
Python Completions536
Haskell Completions102
COBOL Completions7
C Completions74
Total Stars54
% of votes with a positive feedback rating93% of 226
Total "Very Satisfied" Votes200
Total "Somewhat Satisfied" Votes22
Total "Not Satisfied" Votes4
Ad
Contributors
  • debri Avatar
  • jhoffner Avatar
  • bkaes Avatar
  • GiacomoSorbi Avatar
  • Voile Avatar
  • bidouille Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • bornForThis Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • farhanaditya Avatar
  • yLaWy Avatar
Ad