A documentation site builds a search index in the browser. Its first step is to sort all suffixes of a page's text, so that any search term can be found by binary search.
Write suffixOrder(text) that returns the start indexes of all suffixes of text, ordered so the suffixes are in increasing alphabetical order (compare character codes; a shorter suffix that is a prefix of a longer one comes first).
Texts can be 100,000 characters long, and in a repetitive text two suffixes can share thousands of letters, so comparing whole suffixes letter by letter may be too slow.
Input: text = "banana" Output: [5,3,1,0,4,2]
a, ana, anana, banana, na, nana.
Input: text = "abc" Output: [0,1,2]
abc, bc, c are already in order.
0 <= text.length <= 10^5text contains lowercase letters.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #631 Sort Every Suffix. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.