Password
MediumRating 1700CodeforcesString Algorithms (KMP, Z, Hashing)
Approach hintTry it first, then revealHide
Candidates are the borders of the whole string, reached through the chain pi[n-1], pi[pi[n-1]-1], and so on. A border also occurs strictly inside if its length appears as pi[i] for some i < n - 1.