Skip to main content

Command Palette

Search for a command to run...

Long Pressed Name

Published
1 min read
Long Pressed Name
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.

You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.

LeetCode Problem - 925

class Solution {
    // Method to check if 'typed' is a long pressed version of 'name'
    public boolean isLongPressedName(String name, String typed) {
        int i = 0, j = 0;

        // Iterate through 'typed' string
        while (j < typed.length()) {
            // If characters match, move to the next character in both 'name' and 'typed'
            if (i < name.length() && name.charAt(i) == typed.charAt(j)) {
                i++;
                j++;
            } 
            // If current 'typed' character is the same as previous one, move to the next 'typed' character
            else if (j > 0 && typed.charAt(j) == typed.charAt(j - 1)) {
                j++;
            } 
            // If characters don't match and current 'typed' character isn't repeated, return false
            else {
                return false;
            }
        }

        // Check if we have consumed all characters in 'name'
        return i == name.length();
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.