Skip to content
Back to libraryPart 4 · Advanced topics

4.5Selected string techniques

Before you start

It helps to have read 1.3 Arrays and strings, 1.4 Counting and frequency, 2.1 Prefix sums and 2.4 Recursion and backtracking. Overall level: Advanced.

Practice: Selected string techniques

0 of 4 solved

About these problems

Apply, Connect, Reason and Stretch describe difficulty within this topic, not an official contest rating. Open any problem in any order; reading the chapter first is optional.

  1. 1Prefix border lengthsYou are given a string s of lowercase letters. Print, for every i from 1 to |s|, the length of the longest proper prefix of the first i characters of s that is also a suffix of them. A proper prefix is shorter than the whole string it is taken from.ApplyNot started
  2. 2All pattern startsYou are given a pattern p and a text t, both strings of lowercase letters. Find all starting positions where p occurs in t, including overlapping matches. Positions are 1-based.ConnectNot started
  3. 3Shortest repeating blockYou are given a string s of lowercase letters. Find the minimum positive length k such that s is made of one or more copies of its first k characters, written one after another. One copy of the whole string is allowed, so k = |s| always works.ReasonNot started
  4. 4Every full-string borderYou are given a string s of lowercase letters. Print all lengths k with 1 ≤ k < |s| such that the first k characters of s equal the last k characters of s.StretchNot started

Read the lesson