Help me out in this
i need to solve it first to explain u .
that might take some time. till then try on ur own
first use kmp to find prefix which is also suffix i.e prepare lps array . (say p).
If i mod (i - p[i]) == 0 then K = i / (i - p[i]) else K = 1.
how i-p[i] will be period?
Suppose that x is a string of length n. To find the period of x, compute the KMP prefix function of x. The period of x is n - p(n). This is because a periodic string with period k matches itself when shifted forward k characters. So the length n-k prefix of the string must be identical to the length n-k suffix.
the whole idea is inspired from this problem -> link
@aman212yadav
a a b a a b a a b a a b
lps 0 1 0 1 2 3 4 5 6 7 8 9
can you explain with this example?
bro check the link i shared, example is given with explanation.
is this clear now?. .
lol, but mein to aisa kabhi nahi kehta hun
mein to bus puch raha tha ki aaya samjh mein ya nahi.
@aman212yadav okay i am kidding bro this question is good very much intuitive very good question for kmp
yeah it was a good question.
and yeah the whole idea was how u compute period for given string .
period -> n - lps[n] (keep this in mind, can be helpful in verious other string related problems)
u mean n % (n-lps[n]) = 0 right? for n-lps[n] to be its period