The question is to count how many permutations of a string B have an equivalent pattern into a bigger string A. For example, if A="aabbccd"
and B="xx"
, then it should print 3
, since "aa"
, "bb"
, "cc"
are all substrings of A
which share the same pattern as B
.
I have tried to pass the substrings as numbers, such as xx
becomes "11"
and do the same for string A
, but I still can't get it to work. Any ideas? Length can be up to 10^7
.
Here's the code for changing pattern:
void transform(int* dest, char* original, int len) {
int j=1;
Al[original[0]-'a']=j;
dest[0]=j;
j++;
for (int i=1;i<len;i++) {
if (Al[original[i]-'a']==0)
Al[original[i]-'a']=j++;
dest[i]=Al[original[i]-'a'];
}
}
B
have? What would you consider the permutations ofB="xyz";
?