Find Maximum Number of Strings
Updated
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) → 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
More Moveworks interview questions
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