Practice Find Substring With Given Hash Value
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Hard#2156
LeetCode ProblemFind Substring With Given Hash Value
Problem Statement
For a length-k substring t, define its hash as the sum of val(t[j]) * power^j for j from 0 through k - 1, modulo modulo; a has value 1 through z with value 26. Return the earliest length-k substring of s whose hash equals hashValue. A matching substring is guaranteed.
Source: Find Substring With Given Hash Value on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
s = "leetcode", power = 7, modulo = 20, k = 2, hashValue = 0
Output
"ee"
# Example 2
Input
s = "fbxzaad", power = 31, modulo = 100, k = 3, hashValue = 32
Output
"fbx"
Constraints
1 <= k <= s.length <= 2 * 10^4
1 <= power, modulo <= 10^9
0 <= hashValue < modulo
s consists of lowercase English letters only.
The test cases are generated such that an answer always exists.
Related LeetCode Problems
Practice more problems similar to Find Substring With Given Hash Value.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.