Skip to content

Practice Sum of Scores of Built Strings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2223
LeetCode Problem

Sum of Scores of Built Strings

Problem Statement

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 si. The score of si is the length of the longest common prefix between si and sn (Note that s == sn). Given the final string s, return the sum of the score of every si.

Source: Sum of Scores of Built Strings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "babab"
Output
9

# Example 2

Input
s = "azbazbzaz"
Output
14

Constraints

1 <= s.length <= 10^5
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Sum of Scores of Built Strings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.