## Sum of Scores of Built Strings solution leetcode

**Sum of Scores of Built Strings solution leetcode** You are **building** a string `s`

of length `n`

**one** character at a time, **prepending** each new character to the **front** of the string. The strings are labeled from `1`

to `n`

, where the string with length `i`

is labeled `s`

._{i}

- For example, for
`s = "abaca"`

,`s`

,_{1}== "a"`s`

,_{2}== "ca"`s`

, etc._{3}== "aca"

The **score** of `s`

is the length of the _{i}**longest common prefix** between `s`

and _{i}`s`

(Note that _{n}`s == s`

)._{n}

Given the final string `s`

, return* the sum of the score of every *

`s`_{i}

.

**Example 1: Sum of Scores of Built Strings solution leetcode**

Input:s = "babab"Output:9Explanation:For s_{1}== "b", the longest common prefix is "b" which has a score of 1. For s_{2}== "ab", there is no common prefix so the score is 0. For s_{3}== "bab", the longest common prefix is "bab" which has a score of 3. For s_{4}== "abab", there is no common prefix so the score is 0. For s_{5}== "babab", the longest common prefix is "babab" which has a score of 5. The sum of the scores is 1 + 0 + 3 + 0 + 5 = 9, so we return 9.

**Example 2: Sum of Scores of Built Strings solution leetcode**

Input:s = "azbazbzaz"Output:14Explanation:For s_{2}== "az", the longest common prefix is "az" which has a score of 2. For s_{6}== "azbzaz", the longest common prefix is "azb" which has a score of 3. For s_{9}== "azbazbzaz", the longest common prefix is "azbazbzaz" which has a score of 9. For all other s_{i}, the score is 0. The sum of the scores is 2 + 3 + 9 = 14, so we return 14.

**Constraints: Sum of Scores of Built Strings solution leetcode**

`1 <= s.length <= 10`

^{5}`s`

consists of lowercase English letters.