code : https://ideone.com/ZUfpWX

prob : https://www.hackerearth.com/practice/data-structures/advanced-data-structures/suffix-trees/tutorial/ (practice prob).

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!