LeetCode solutions

3617. Find the Original Typed String I

My accepted Python solution to LeetCode problem 3617, Find the Original Typed String I, running in 46ms.

  • Difficulty: Easy
  • Python
  • Runtime 46ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 46ms, memory 17.2MB, accepted 2026-01-01.

python
class Solution:
    def possibleStringCount(self, word: str) -> int:
        # Count groups of consecutive same characters
        # For each group of size k > 1, we have k-1 ways to reduce it (or keep it as is)
        # Plus 1 for the original string
        count = 1  # original string
        i = 0
        while i < len(word):
            j = i
            while j < len(word) and word[j] == word[i]:
                j += 1
            # Group of size j-i
            group_size = j - i
            if group_size > 1:
                count += group_size - 1
            i = j
        return count

Source