Strings With No k Consecutive Identical Characters
Updated
Problem statement
You are given two integers:
n: length of stringk: maximum allowed consecutive identical characters
A string is invalid if it contains k or more consecutive identical characters.
Return the total number of strings of length n formed using lowercase English letters
such that no character appears k or more times consecutively.
Return the answer modulo 10^9 + 7.
Function
stringsWithNoKConsecutiveIdenticalCharacters(n: int, k: int) → intExamples
Example 1
n = 3k = 2return = 16250
Total strings of length 3 is 26^3 = 17576.
Invalid strings are those with at least one adjacent equal pair.
For this case, the valid count is 16250.
Constraints
1 <= n <= 10^51 <= k < n
More Salesforce Online Assessment questions
- Count Subarrays With Product Equal to KOA · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
- Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
- Run-Length String CompressionOA · Seen Sep 2026
- Maximum Requests in WindowOA · Seen Sep 2026
- Final Pod Counts After LogsOA · Seen Aug 2026
- Minimum Removals to Balance ArrayOA · Seen Aug 2026
- Is This Date a Weekend?OA · Seen Aug 2026
- Maximum Barbell WeightOA · Seen Jul 2026
Similar questions at other companies
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Count Combinations Using Weights One Through KConfluent · OAConfluent interview questions
- Count Bounded Share TransactionsOptiver · OAOptiver interview questions
- Count Strictly Increasing Subsequences of Length 3IBM · OAIBM interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Count Subsequences Without Three Equal-Parity Elements in a RowGoogle · OAGoogle interview questions
- Count Equal-Frequency SubsequencesExpedia · OAExpedia interview questions
- Find Encrypted NumberAmazon · OA