Corrected

The previous solution didn't work for string containing duplicated repetitions. Eg. abaaabaa