Sort all prefixes of a string lexicographically and print the end index of each prefix in that order.
Medium4SortingStringImplementationNo attempts yetTime limit2sMemory limit512 MBA suffix array is what you get by sorting every suffix of a string in lexicographic order and then writing down, in that order, the index where each suffix starts. Take the string 'banana'.
So the suffix array of 'banana' is {5, 3, 1, 0, 4, 2}.
Taekhee and Namgyu, members of the problem solving club Morgorithm at Yonsei University, were working through a string problem together. Here is part of the conversation.
The two of them got stuck. Write the program that builds the prefix array for them.
The first line contains a string S made of lowercase English letters. (1≤∣S∣≤100000)
Print ∣S∣ lines. Sort every prefix of S in lexicographic order, then print the index where each prefix ends, from the first prefix in that order to the last. Indices into the string start at 0.