I got an array that store the position of the characters in a string and they are stored in their ASCII character order, using Counting Sort algorithm.
For example, with a string ABABAC, the the first position is 0,
the array is stored as this order:
0,2,4,1,3,5where 0,2,4 are A, 1,3 are B and 5 is C.
I then use this array to check if there is common pattern among the characters.
I use a while loop, since I know 0 and 2 are A, I increment their pointers to 1 and 3. I compare 1 with 3, they have same characters. I increment the pointers again. 2 compare with 4, they have different characters. Thus, I know there exist a common pattern AB.
After this, I use 0 to compare with 4 again, to check for common pattern.
But this way of doing while loop is not efficient. Is there any other algorithms that is faster?
Thanks for your help!