Medium
You are given two integers n and k.
A string s of length n consisting of lowercase English letters is valid if s[i] and s[i + k] are different for every index 0 <= i < n - k.
Return the number of valid strings of length n, modulo 109 + 7.
Example 1:
Input: n = 3, k = 1
Output: 16250
Explanation:
- At index 0, we can have 26 options, from
'a'to'z'. - At index 1, we can have 25 options, from
'a'to'z'except the character at index 0. - At index 2, we can have 25 options, from
'a'to'z'except the character at index 1. - The total number of valid strings is
26 * 25 * 25 = 16250.
Example 2:
Input: n = 3, k = 2
Output: 16900
Explanation:
- At index 0, we can have 26 options, from
'a'to'z'. - At index 1, we can have 26 options, from
'a'to'z'. - At index 2, we can have 25 options since it must be different from the character at index 0.
- The total number of valid strings is
26 * 26 * 25 = 16900.
Constraints:
2 <= n <= 1051 <= k < n