KMP prefix table
Every number belongs to corresponding prefix (“a”, “ab”, “aba”, …) and for each prefix it represents length of longest suffix of this string that matches prefix. We do not count whole string as suffix or prefix here, it is called self-suffix and self-prefix (at least in Russian, not sure about English terms). So we have … Read more