SalesforceOA #41
Strings With No k Consecutive Identical Characters
Estimated MediumJudge-ready
Topics (AI-labelled)DP BasicsPrefix & Ranges
Count the lowercase English strings of length n that do not contain k or more consecutive identical letters, modulo 1000000007. At most k−1 identical letters may appear consecutively; do not misread this as allowing k.
Input
The input gives n k. Full original bounds: 1≤n≤100000, 1≤k<n, so a valid n is in fact ≥2; do not change this to k≤n or change the forbidden length to k+1.
Output
Output one integer answer.
Example 1
Input:
3 2
Output:
16250
Example 2
Input:
2 1
Output:
0
Example 3
Input:
5 4
Output:
11880050
Example notes
The outputs of the three public examples are, in order: 16250; 0; 11880050. They have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…