educative.io

Why are we adding to the output without checking whether the pattern for which the hash matches

Rabin Karp does not guarantee unique hash values so why are we adding to the output here without verifying the string? Hash collision is still possible I believe

Hi @HARSHITA_KRISHNA, the Rabin Karp algorithm does indeed lead to collisions, depending on the type of hash function used. However, for the case of this problem and its specified constraints, the polynomial rolling hash function can never give duplicate hash values. Therefore, we do not verify the string when a match is found.