With “abaabaaba” the answer is 3 and with “abaabaabaabaaba” the answer is 5. Using more than three letters is also possible. With “cbabccbabccbabc” we get 3.
My first thought was “ababa”. That fails because the a’s at either end up next to each other. From that observation I realised that we need to double the other a’s. Another way to think about it is using your observation. For s = “aaaa” we get 4. If we replace each ‘a’ with a palindrome, we will always get at least 4.
“abbaabba” is also interesting and gives 4. This is different than my other examples because there are two unique palindromes that can be formed by shifting this one: “abbaabba” and “baabbaab”.
How to deal with the problem of rounding of powers of ‘p’ when the power value crosses mod value?
As in, when we are comparing hash and reverse hash, one hash is multiple of other hash(as given in prerequisite). But that holds true only if the power values round up at the same point for given string.
now if string under consideration is [2 7].
Suppose that while computing prefix array, power value rounds off at index 5.
And suppose that while computing suffix array, power value rounds off at index 7.
So, the hash[2 7] using prefix array CANT BE EQUAL to hash[2 7] using suffix array.
These factors depend strictly on your hash function. Check what the setter and tester have done, they did something different. They made it such that, instead of checking if hsh is a multiply of hsh2 or not, they simply checked for hsh1==hsh2. Give a read to editorial if they havent. Try to get what is represented by the hash function, it will be easier to understand it.
Editorial solution is expected to be put up so that we can relate with the editorial. Setter solution has been poorly explained and I couldn’t get the logic behind the setter’s code.
Could you please tell me the logic behind setter’s code?