Complete the code to create a suffix array by sorting all suffixes of the string s.
suffixes = [s[i:] for i in range(len(s))] suffix_array = sorted([1])
The suffix array is created by sorting all suffixes of the string. Here, suffixes is the list of all suffixes, so sorting suffixes gives the suffix array.
Complete the code to build the suffix array as a list of starting indices of sorted suffixes.
suffix_array = sorted(range(len(s)), key=lambda i: [1])
i itself as the key.The suffix array stores the starting indices of suffixes sorted lexicographically. The key function lambda i: s[i:] sorts indices by their suffixes.
Fix the error in the code that tries to build a suffix array but incorrectly sorts characters instead of suffixes.
suffix_array = sorted(range(len(s)), key=lambda i: s[[1]])
i.len(s).The code sorts indices by the character at position i, which is correct to access the first character of each suffix. However, sorting by only one character is not a full suffix array. Still, the blank must be i to avoid errors.
Fill both blanks to create a dictionary comprehension mapping each suffix to its starting index.
{s[i:]: [1] for i in range([2])}The dictionary comprehension maps each suffix s[i:] to its starting index i. The range must go from 0 to len(s) to cover all suffixes.
Fill all three blanks to create a suffix array by sorting indices with a key function that returns suffixes.
suffix_array = sorted(range([1]), key=lambda [2]: s[[3]:])
len(s).The suffix array is built by sorting indices from 0 to len(s). The key function takes an index i and returns the suffix s[i:] for sorting.