3330. Find the Original Typed String I LeetCode Solution
In this guide, you will get 3330. Find the Original Typed String I LeetCode Solution with the best time and space complexity. The solution to Find the Original Typed String I problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Find the Original Typed String I solution in C++
- Find the Original Typed String I solution in Java
- Find the Original Typed String I solution in Python
- Additional Resources

Problem Statement of 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:
Input: word = “abbcccc”
Output: 5
Explanation:
The possible strings are: “abbcccc”, “abbccc”, “abbcc”, “abbc”, and “abcccc”.
Example 2:
Input: word = “abcd”
Output: 1
Explanation:
The only possible string is “abcd”.
Example 3:
Input: word = “aaaa”
Output: 4
Constraints:
1 <= word.length <= 100
word consists only of lowercase English letters.
Complexity Analysis
- Time Complexity: O(n)
- Space Complexity: O(1)
3330. Find the Original Typed String I LeetCode Solution in C++
class Solution {
public:
int possibleStringCount(string word) {
int ans = 1;
for (int i = 1; i < word.length(); ++i)
if (word[i] == word[i - 1])
++ans;
return ans;
}
};
/* code provided by PROGIEZ */
3330. Find the Original Typed String I LeetCode Solution in Java
class Solution {
public int possibleStringCount(String word) {
int ans = 1;
for (int i = 1; i < word.length(); ++i)
if (word.charAt(i) == word.charAt(i - 1))
++ans;
return ans;
}
}
// code provided by PROGIEZ
3330. Find the Original Typed String I LeetCode Solution in Python
class Solution:
def possibleStringCount(self, word: str) -> int:
return 1 + sum(a == b
for a, b in itertools.pairwise(word))
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.