Suffix Arrays & the Longest Repeat
In short: a suffix array is every suffix of a string, sorted alphabetically — stored as just their starting indices, not copies of the text. Once sorted, two suffixes that share a long prefix sit next to each other, because sorting groups anything alike. The LCP array (longest common prefix) measures exactly how much each neighbouring pair shares. Together they turn "does this substring repeat, and how much" from a scan-everything question into a read-the-neighbours question.

Sorting suffixes instead of comparing substrings
"banana" has 6 suffixes: banana, anana, nana, ana, na, a.
Sorted alphabetically:
The array stores indices, [5, 3, 1, 0, 4, 2], not the suffix strings
themselves — slicing s[i:] is only for printing. Building it this way, by
sorting Python string slices, is O(n² log n) in the worst case (each
comparison can itself cost O(n)), fine for a lesson-sized string; production
suffix-array builders use O(n log n) radix-style construction, which is
past this lesson's scope.