Problem · Dynamic Programming
Find Maximum Number of Strings
Learn this problemProblem statement
Given integers n and k, count the lowercase English strings of length n such that the absolute difference between the alphabet positions of every pair of adjacent characters is at most k.
For example, the difference between f and c is 3, while the difference between b and a is 1.
Return the count modulo 1,000,000,007.
Function
findMaxNumberOfStrings(n: int, k: int) → intExamples
Example 1
n = 2k = 3return = 170
For example, if we take the string "ab", the difference between a and b is 1. Thus this is a valid string.
Similarly the strings "cd", "ce", "cf", "gi" are also valid.
Like this there are 170 strings of length n = 2 that are fulfilling the condition.
Constraints
1 <= n <= 10^61 <= k <= 25