JuniorString

Find the Original Typed String I

Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times.

Although Alice tried to focus on her typing, she is aware that she may still have done this at most once.

You are given a string word, which represents the final output displayed on Alice's screen.

Return the total number of possible original strings that Alice might have intended to type.

Example 1
Inputword = "abbcccc"
Output5
The possible strings are: "abbcccc", "abbccc", "abbcc", "abbc", and "abcccc".
Example 2
Inputword = "abcd"
Output1
The only possible string is "abcd".

Constraints

  • 1 <= word.length <= 100
  • word consists only of lowercase English letters.

Asked at 7 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate