I have a question: if we let rolling hash overflow, does it affect the correctness of Rabin-Karp algorithm? Could you give a solid example that the overflow indeed will affect correctness?
That is something like same string e.g. "abcd" will give different hash values when you directly compute from "abcd" or from "eabcd" (hash("eabc") - hash("e") * R^3) * R + hash("d")
hash("abcd") != (hash("eabc") - hash("e") * R^3) * R + hash("d") if we allow int/long overflow