Why am I getting an error and how to resolve it?


#1

void calculateLps(vector &lps,string s,long long l)
{
lps[0]=0;
long long len=0;
long long i=1;
while(i<l)
{
if(s[i]==s[len])
{
len++;
lps[i]=len;
i++;
}
else
{
if(len!=0)
{
len=lps[len-1];
}
else
{
lps[i]=0;
i++;
}
}
}
}
long long indexOf(string txt,string pat)
{
long long M=pat.length();
long long N=txt.length();
vector lps(M);
calculateLps(lps,pat,M);
long long i = 0; // index for txt[]
long long j = 0; // index for pat[]
while (i < N)
{
if (pat[j] == txt[i])
{
j++;
i++;
}

    if (j == M) { 
        return i - j; 
        j = lps[j - 1]; 
    } 
    
    else if (i < N && pat[j] != txt[i]) 
    { 
        if (j != 0) 
            j = lps[j - 1]; 
        else
            i = i + 1; 
    } 
}
return -1;

}
long long minNumberOfRotation(string str)
{
string two = str + str;
// cout<<indexOf(two.substr(1), str);
return indexOf(two.substr(1), str)+1;
}
long long lcm(long long a,long long b)
{
return ((a*b)%1000000007)/__gcd(a,b);
}
int Solution::solve(vector &A)
{
long long max=1;
for (auto s : A)
{
// cout<<“H”;
long long numberOfRotation = minNumberOfRotation(s);

    for (long long i = 1; i <= 2 * numberOfRotation + 1; i ++) 
    {
        if (((i * (i + 1)) / 2) % numberOfRotation == 0) 
        {
            max = lcm(max,i);
            break;
        }
    }
}
return max%1000000007;

}