Problem · Dynamic Programming
Strings With No k Consecutive Identical Characters
See Salesforce hiring insightsYou 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.
Examples
01 · Example 1
n = 3 k = 2 return = 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 problems
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
- Longest Subsequence which is a SubstringOA · Seen Dec 2025
public int stringsWithNoKConsecutiveIdenticalCharacters(int n, int k) {
// write your code here
}
n3
k2
expected16250
sign in to submit