w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Compute hash of a substring given the hashes of all prefixes of the string

The hash of the substring s[A..B] is

hash[B] - R^(B - A + 1) * hash[A - 1] mod M

Use modular exponentiation to compute the power of R mod M. And no, unless you precomputed the powers of R it is not possible to compute that in O(1).

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.