Find the Original Typed String II
Real-world version: Counting the Labels the Stamping Could Have MeantThe statement here is our own: the same inputs, outputs and technique.
A label was made by pressing one stamp at a time, and a stamp held down too long leaves several copies of its letter in a row. The finished label reads word.
So the label falls into runs of one repeated letter, and a run of L letters could have come from anywhere between 1 and L presses of that stamp.
Return how many different intended labels hold at least k letters. Two intended labels differ when some run came from a different number of presses. Report the count modulo 10^9 + 7.
Examples
Example 1
- Input
- word = "aabbcc", k = 4
- Output
- 7
The three runs each hold two letters, so eight intended labels are possible, running from three letters up to six. Only the shortest, one press per run, falls below four.
Example 2
- Input
- word = "aaa", k = 2
- Output
- 2
The single run of three could have come from one, two or three presses, and the last two of those hold at least two letters.
Example 3
- Input
- word = "ab", k = 2
- Output
- 1
Neither letter repeats, so only one intended label exists, and it holds two letters.
Constraints
- 1 <= word.length <= 5 * 10^5
- word holds only lowercase English letters
- 1 <= k <= 2000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def possible_string_count(word: str, k: int) -> int:public int possibleStringCount(String word, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Jump Game VIIReal-world version: Pontoon Crossing With A Hop RangeMedium
- Is SubsequenceReal-world version: Shorthand Fits the LabelEasy
- Maximum Repeating SubstringReal-world version: Longest Run of a Repeated TagEasy
- Maximum Score After Splitting a StringReal-world version: Cutting the Strip for the Best ScoreEasy