When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

Newaj_69's blog

By Newaj_69, history, 6 years ago, In English

I was trying to solve the problem http://www.spoj.com/problems/MINMOVE/ but unfortunately couldn't. My solution idea was:

1.First of all I checked whether all the character is same or not. If it is same then the answer is 0. Example: aaa answer should be 0.

2.Otherwise, I have concatenate the string at the back of the string and then added a "$" at last.

3.Then I build the suffix array (n*log(n)).

4.At last I traversed the suffix array whenever I got a value in the suffix array less then the string.size()/2 then I printed the value.

Now, I have no idea what to do.Any help or suggestions would be appreciated.

code: https://ideone.com/QHcYhW

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Good day to you,

does it necessary have to be your "approach"? I would rather recomment looking onto Booth's Algorithm algorithm, which could find the minimal rotation of string (and is pretty short to implement).

Hope it will help.

Good Luck & Have Nice Day ^_^

  • »
    »
    6 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    Yes, I think it is necessary because then I will have the opportunity for rectifying my approach. But thank you. After solving this problem in my way , I will try to learn your suggested algorithm too.