3 ms·
Have a rolling hash and compute all hashes of the prefixes in one go, in O(N). Per-prefix cost of hashes gets amortized to O(1).
by planede 4y ago
Have a rolling hash and compute all hashes of the prefixes in one go, in O(N). Per-prefix cost of hashes gets amortized to O(1).