Problems > Longest Border

Longest Border

Difficulty: 1500 2000 ms 128 MB

strings

A border of S is a string that is both a proper prefix and a proper suffix of S. Print the length of the longest border (0 if none).

Input: one line with a lowercase string.

Output: the longest border length.

Constraints:

  • 1 ≤ |S| ≤ 104

Sample Tests

Input 1
abcab
Output 1
2
Input 2
aaaa
Output 2
3

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.