`{"id":"68274fac-7d73-4f89-a24d-2800b595000c","name":"String Polynomial Hashing","description":"Given a string S, print the hash code of that string using Polynomial Hashing.\r\nNote: Use prime number = 31 and print the answer mod 1000000007.","inputFormat":"The first line contains an integer T denoting the number of test cases.\r\nT lines follow each containing a string S.","outputFormat":"Print an integer (the hashcode of the string) mod 1000000007 and take prime number 31 for hashing.","constraints":"String s consists of only lowercase English alphabets\r\n|S| &lt;= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static long hashCode(String s) {\r\n //Write your code here\r\n // NOTE: use prime number = 31 and mod = 1000000007\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int T = scn.nextInt();\r\n while (T-- > 0) {\r\n String s = scn.next();\r\n System.out.println(hashCode(s));\r\n }\r\n scn.close();\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\nab\r\nabc\r\nabcd\r\nabc\r\nxyz\r\npqr","sampleOutput":"63\r\n2946\r\n122110\r\n2946\r\n25785\r\n17841","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"a2073e25-96a1-4875-b400-f40bbe2edd95","name":"Text Processing For Experts","slug":"text-processing-for-experts-859","type":0},{"id":"ca311230-0a6f-4191-b99a-e259f0e2be15","name":"String Polynomial Hashing","slug":"string-polynomial-hashing","type":1}],"next":{"id":"d3bd62d8-61d1-41fc-bd28-ed0e9c07a59a","name":"Diane","type":1,"slug":"diane"},"prev":{"id":"69a201c4-0167-4796-8f47-94965d7eaabf","name":"Coin Rows","type":1,"slug":"coin-rows"}}}`

# String Polynomial Hashing

Given a string S, print the hash code of that string using Polynomial Hashing. Note: Use prime number = 31 and print the answer mod 1000000007.

`{"id":"68274fac-7d73-4f89-a24d-2800b595000c","name":"String Polynomial Hashing","description":"Given a string S, print the hash code of that string using Polynomial Hashing.\r\nNote: Use prime number = 31 and print the answer mod 1000000007.","inputFormat":"The first line contains an integer T denoting the number of test cases.\r\nT lines follow each containing a string S.","outputFormat":"Print an integer (the hashcode of the string) mod 1000000007 and take prime number 31 for hashing.","constraints":"String s consists of only lowercase English alphabets\r\n|S| &lt;= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static long hashCode(String s) {\r\n //Write your code here\r\n // NOTE: use prime number = 31 and mod = 1000000007\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int T = scn.nextInt();\r\n while (T-- > 0) {\r\n String s = scn.next();\r\n System.out.println(hashCode(s));\r\n }\r\n scn.close();\r\n }\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\nab\r\nabc\r\nabcd\r\nabc\r\nxyz\r\npqr","sampleOutput":"63\r\n2946\r\n122110\r\n2946\r\n25785\r\n17841","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"a2073e25-96a1-4875-b400-f40bbe2edd95","name":"Text Processing For Experts","slug":"text-processing-for-experts-859","type":0},{"id":"ca311230-0a6f-4191-b99a-e259f0e2be15","name":"String Polynomial Hashing","slug":"string-polynomial-hashing","type":1}],"next":{"id":"d3bd62d8-61d1-41fc-bd28-ed0e9c07a59a","name":"Diane","type":1,"slug":"diane"},"prev":{"id":"69a201c4-0167-4796-8f47-94965d7eaabf","name":"Coin Rows","type":1,"slug":"coin-rows"}}}`

Editor

# String Polynomial Hashing

medium

Given a string S, print the hash code of that string using Polynomial Hashing. Note: Use prime number = 31 and print the answer mod 1000000007.

## Constraints

String s consists of only lowercase English alphabets |S| <= 10^5

## Format

### Input

The first line contains an integer T denoting the number of test cases. T lines follow each containing a string S.

### Output

Print an integer (the hashcode of the string) mod 1000000007 and take prime number 31 for hashing.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 ab abc abcd abc xyz pqr```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}63 2946 122110 2946 25785 17841```

Discussions

Show Discussion

Related Resources