Rolling Hash Variable

Programming Interview Hard 5 views
Back to Questions

Problem Description

You're given {x}. Compute rolling hash: h=0; for each char c: h=(h*B+ord(c))%M. Output h.

Input Format

Line1: s. Line2: B M.

Output Format

One integer hash.

Sample Test Case

Input:
abc 911382 1000000007
Output:
98303017

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next