Problem · Dynamic Programming

Find Maximum Number of Strings

Learn this problem
MediumMoveworksFULLTIMEINTERNOA

Problem 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) → int

Examples

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^6
  • 1 <= k <= 25

More Moveworks problems

drafts saved locally
public int findMaxNumberOfStrings(int n, int k) {
  // write your code here
}
n2
k3
expected170
checking account