All problems
Suffix Array (Naive)
Problem
Return the starting indices of all suffixes of s sorted in lexicographic order.
For small inputs, sorting indices with the suffix itself as the comparison key is acceptable and fully deterministic. Return an empty list for an empty string.
Hint
For the string banana the suffixes start a, ana, anana, banana, na, nana.
Test cases
case 1
in: ["banana"]
expected: [5,3,1,0,4,2]
case 2
in: ["cba"]
expected: [2,1,0]
case 3
in: [""]
expected: []
case 4
in: ["a"]
expected: [0]
case 5
in: ["aaaa"]
expected: [3,2,1,0]
Starter codePython
def suffix_array_naive(s):
# Your code here
pass5 test cases · run your code against them in the editor