LeetCode 3330: Find the Original Typed String I Solution

Master LeetCode problem 3330 (Find the Original Typed String I), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

3330. Find the Original Typed String I

Easy

Problem Explanation

Explanation

To solve this problem, we can iterate through the input string word and count the number of occurrences of each character. For each character, we calculate the number of ways it can be typed (taking into account that it might have been typed multiple times). The total number of possible original strings is the product of the number of ways each character can be typed. We need to consider the cases where a character is typed once, twice, or more than twice.

Solution Code

class Solution {
    public int findOriginalString(String word) {
        int result = 1;
        int count = 0;
        for (int i = 0; i < word.length(); i++) {
            count++;
            if (i == word.length() - 1 || word.charAt(i) != word.charAt(i + 1)) {
                result *= count;
                count = 0;
            }
        }
        return result;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 3330 (Find the Original Typed String I)?

This page provides optimized solutions for LeetCode problem 3330 (Find the Original Typed String I) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 3330 (Find the Original Typed String I)?

The time complexity for LeetCode 3330 (Find the Original Typed String I) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 3330 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 3330 in Java, C++, or Python.

Back to LeetCode Solutions