Count how many original strings could have produced a given typed string after accidental repeated keystrokes.
A user intended to type a string, but some key presses may have been repeated consecutively. You are given the final typed string typed, which is formed by taking an unknown original string and expanding some characters into one or more consecutive copies.
Your task is to determine how many different original strings could have produced typed under this process.
More precisely, if the original string contains a character c, then in the typed result that character may appear as a contiguous block of one or more c characters. Different original strings are counted as distinct.
Return the number of possible original strings.
typed.typed.0 <= typed.lengthtyped contains lowercase English letters in the most common formulation of this problem.typed into groups of equal characters.typed.The string represents the final result after some characters may have been repeated consecutively.
Example 1
Input
typed = "abbccc"
Output
12
Explanation
The string can be viewed as runs: a, bb, ccc. Each run may have come from 1 up to its length repeated presses, contributing multiple possible original forms. The total number of original strings is the product of the choices across runs, minus invalid interpretations that would break the run structure.
Example 2
Input
typed = "aaaa"
Output
4
Explanation
The possible original strings are a, aa, aaa, and aaaa.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.