Given a name and a typed-name of a person. Sometimes, when typing a vowel [aeiou], the key might get long pressed, and the character will be typed 1 or more times. The task is to examine the typed-name and tell if it is possible that typed name was of person’s name, with some characters (possibly none) being long pressed. Return ‘True‘ if it is, else ‘False‘.
Note: name and typed-name are separated by space with no space in between individuals names. Each character of the name is unique.
Input: str = “geeks”, typed = “geeeeks”
The vowel ‘e’ repeats more times in typed and all other characters match.
Input: str = “alice”, typed = “aallicce”
Here ‘l’ and ‘c’ are repeated which not a vowel.
Hence name and typed-name represents different names.
Input: str = “alex”, typed = “aaalaeex”
A vowel ‘a’ is extra in typed.
Approach: The idea is based on Run Length Encoding. We consider only vowels and count their consecutive occurrences in str and typed. The count of occurrences in str must be less.
Below is the implementation of above approach.
Time Complexity : O(m + n)
Auxiliary Space : O(1)
- String slicing in Python to check if a string can become empty by recursive deletion
- Check if a string can be converted to another string by replacing vowels and consonants
- Check if a string can become empty by recursively deleting a given sub-string
- Queries to check if string B exists as substring in string A
- Check if a string can be obtained by rotating another string 2 places
- Check if a string can be obtained by rotating another string d places
- Check whether second string can be formed from characters of first string
- Check if the given string is shuffled substring of another string
- Check if a string contains a palindromic sub-string of even length
- Check if a string can be formed from another string using given constraints
- Check if a string can be repeated to make another string
- Check if a given string is sum-string
- Check if the given string is K-periodic
- Check if a string is Isogram or not
- Check if it is possible to transform one string to another
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.