FastPrepFastPrep
Problem Brief

Good Strings

OA

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.

1Example 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.

2Example 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

Limits and guarantees your solution can rely on.

  • n ≤ 105
  • d ≤ 25
public int goodStrings(int n, int d) {
  // write your code here
}
Input

n

2

d

2

Output

124

Sign in to submit your solution.