Compute the total score of a string by summing the lengths of the longest common prefix between the string and each of its suffixes.
Given a string , define the score of a suffix as the length of the longest common prefix between and . The score of the whole string is the sum of the scores of all suffixes.
Your task is to return that total score.
This is a string-matching style problem: for every starting position, compare the suffix against the original string and accumulate the prefix match length.
Example 1
Input
s = "babab"
Output
9
Explanation
Suffix scores are:
Example 2
Input
s = "aaaaa"
Output
15
Explanation
Every suffix matches the full prefix as much as possible: 5 + 4 + 3 + 2 + 1 = 15.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.