My problem is to find the repeating sequence of characters in the given array. simply, to identify the pattern in which the characters are appearing.
Using C++:
//Splits the string into the fragments of given size
//Returns the set of of splitted strings avaialble
set split(string s, int frag)
{
set uni;
int len = s.length();
for(int i = 0; i < len; i+= frag)
{
uni.insert(s.substr(i, frag));
}
return uni;
}
int main()
{
string out;
string s = "carpentercarpenter";
int len = s.length();
//Optimistic approach..hope there are only 2 repeated strings
//If that fails, then try to break the strings with lesser number of
//characters
for(int i = len/2; i>1;--i)
{
set uni = split(s,i);
if(uni.size() == 1)
{
out = *uni.begin();
break;
}
}
cout<