FastPrepFind Maximum Number of Strings
Problems/Find Maximum Number of Strings

Find Maximum Number of Strings

Moveworks logoMoveworks● MediumFULLTIMEINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Corrected on 2026-07-19 to return the count modulo 1,000,000,007, because the reported range n cannot fit the full count in a 32-bit integer. The judged core task matches the visible source at about 98%.

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 interview questions

  • Underline Shortest Unique SubstringsPHONE SCREEN · Seen Oct 2026
  • Word BreakONSITE INTERVIEW · Seen Sep 2026
  • Minimum Moves to Sort ArrayOA · Seen Jul 2024
  • Number of Balanced StringsOA · Seen Jul 2024
  • Get Minimum Operations to Sort ArrayOA · Seen Jul 2024

Similar questions at other companies

  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
  • Find Encrypted NumberAmazon · OA
  • Valid PasswordsMathWorks · OAMathWorks interview questions
  • Coloring HousesSnowflake · OASnowflake interview questions
  • Count Distinct Binary Search TreesC3.ai · OAC3.ai interview questions
  • Magic Number Range CounterGraviton · OA
  • Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
  • Stable Workload Redistribution TreesTower Research Capital · OA
  • Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
All Moveworks interview questionsSee Moveworks hiring insights
Saved
class Solution {
    public int findMaxNumberOfStrings(int n, int k) {
      // write your code here
    }

}
Checking account…