Problem · Dynamic Programming
Good Strings
Learn this problemProblem statement
You are given two integers n and d. Returns the numbers of Good Strings having length n and absolute difference between the adjacent characters 'a' to 'z' is not more than d.
a and z have absolute difference 25.
b and c have absolute difference 1.
Function
goodStrings(n: int, d: int) → int
GoodStrings has the following parameters:
n: The size of the string.d: The difference.
Returns
int number of Good Strings mod 10^9 + 7.
Examples
Example 1
n = 2d = 2return = 124There are 124 Good Strings of length 2 where the absolute difference between adjacent characters is not more than 2.
Example 2
n = 3d = 5return = 2596There are 2596 Good Strings of length 3 where the absolute difference between adjacent characters is not more than 5.
Constraints
n≤ 105d≤ 25