AlgoLounge

Alice Typing Problem

medium

Alice may have held a key too long at most once while typing. Count the number of possible original strings she could have intended.

Examples

Example 1

Input:  "aaa"
Output: 3

Could have intended "a", "aa", or "aaa"

Example 2

Input:  "abc"
Output: 1

No consecutive duplicates, so only "abc" is possible

Example 3

Input:  "aaaabb"
Output: 5

One group can shrink (first group: 3 options, second group: 1 option) or no mistake

Constraints

  • At most one typing mistake occurred
  • Groups of identical chars indicate possible mistakes
TypeScript
Loading editor…
List of test cases (11)
Case 1
typed = "aaa"
Case 2
typed = "abc"
Case 3
typed = "aabbcc"
Case 4
typed = "aaaa"
Case 5
typed = "abcccde"
Case 6
typed = "aaaabbbc"
Case 7
typed = "a"
Case 8
typed = "aabbccdd"
Case 9
typed = "zzzzz"
Case 10
typed = "abcdef"
Case 11
typed = "aaaabb"