Rabin-Karp Rolling Hash Search

medium
Unit 14 · Strings & BFS0/3 to milestone

Find all start indices where pattern occurs in text using Rabin-Karp: compare rolling polynomial hashes (base 256, modulus 1_000_000_007) and confirm candidate matches with a direct comparison (so hash collisions never produce false positives).

Also implement has_repeat(text, k): return True if any substring of length k occurs at least twice, using the same rolling hash and a dictionary of hash → start positions.

#strings#hashing2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Rabin-Karp Rolling Hash Search · TechGradify