Find the Original Typed String I - Problem
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.
Input & Output
Example 1 — Multiple Groups
$
Input:
word = "aabbaa"
›
Output:
4
💡 Note:
Three groups of consecutive duplicates: 'aa', 'bb', 'aa'. Each can be shortened by one character, plus the original string. Total: 1 + 3 = 4
Example 2 — Single Characters
$
Input:
word = "abc"
›
Output:
1
💡 Note:
No consecutive duplicate characters, so only the original string 'abc' is possible
Example 3 — One Long Group
$
Input:
word = "aaaa"
›
Output:
2
💡 Note:
One group of 4 consecutive 'a's can be shortened to 3 'a's, plus the original. Total: 1 + 1 = 2
Constraints
- 1 ≤ word.length ≤ 100
- word consists of lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Alice's Output
The final typed string 'aabbaa' displayed on screen
2
Identify Mistakes
Find groups where Alice might have held keys too long
3
Count Possibilities
Each group adds one potential original string
Key Takeaway
🎯 Key Insight: Each consecutive duplicate group represents one potential typing mistake that can be 'undone'
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code