Description
Solutions
Good Strings

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 Description

GoodStrings has the following parameters:

  1. n: The size of the string.
  2. d: The difference.

Returns

int number of Good Strings mod 10^9 + 7.

Example 1:

Input:  n = 2, d = 2
Output: 124
Explanation:

There are 124 Good Strings of length 2 where the absolute difference between adjacent characters is not more than 2.

Example 2:

Input:  n = 3, d = 5
Output: 2596
Explanation:

There are 2596 Good Strings of length 3 where the absolute difference between adjacent characters is not more than 5.

Constraints:
    • n ≤ 105
    • d ≤ 25
Thumbnail 0
Testcase

Result
Case 1

input:

output: