dsa2 min read
Longest Duplicate Substring [Hard] — Binary Search + Rolling Hash
Find the longest substring that appears at least twice using binary search on length and Rabin-Karp rolling hash for O(n log n) average time.
Read →
webcoderspeed.com
5 articles
Find the longest substring that appears at least twice using binary search on length and Rabin-Karp rolling hash for O(n log n) average time.
Find all 10-letter DNA sequences that appear more than once. Use rolling hash (4-bit per char) or set of seen substrings.
Master advanced string algorithms: KMP failure function for O(n) pattern matching, Z-algorithm for all prefix matches, Rabin-Karp rolling hash, and suffix arrays for substring queries.
Rabin-Karp uses a rolling polynomial hash to match patterns in O(n+m) expected time. The key is updating the hash in O(1) as the window slides.
Complete recap of all 20 string algorithm problems: pattern recognition guide, algorithm selection, and complexity reference.