I am getting wrong answer for last 2(UPD : 3days lol) days. Didn’t able to find the bug! please help.
In simple words Ques just asked to sort all the suffix and print at which index suffix with sortedIndex ‘j’ starts!
My approach : i have just created a suffix tree and then just do a dfs on the tree and keep counts of number of indexes visited(end_Of_Curr_Node - start_Of_Curr_Node + 1) upto the current node. Now, as we reach leaf node(as we have inserted a unique ‘$’ character so, all the suffixes must end in root) we have the count of the number of indices visited and to get the index of the suffix in the original string we just subtract it by lenghtOfString.
Why I think that this is correct? : I start doing dfs from ‘0’ to ‘255’ and so ensures that we visit each valid suffixes in lexographical order and so, the first reached leaf is the one which comes first when we sort all the substrings!
It will take time. I will have to understand the complete article so that I can make sense of the question. Can you explain the question in simpler terms, along with what you did?
I am expecting 2 3 4 5 0 6 1 as the output, because substring starting from index 0 is “abXXX” while substring from index 4 and 5 are “aab” and “ab”. And I expected index 1 to be last as it started with b.
I am sorry I took so much time, it isnt easy to debug because of lack of correct code, and my understanding of that question. I have to test all the input and your output with pen and paper (wont be surpirsed if I committed error here )