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)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Python | Print the initials of a name with last name in full
- Check if a string can become empty by recursively deleting a given sub-string
- Check if a given string is sum-string
- Check if a string can be formed from another string using given constraints
- Check if the given string is shuffled substring of another string
- Check if left and right shift of any string results into given string
- Check if a given string is a Reverse Bitonic String or not
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Check whether given string can be generated after concatenating given strings
- Check if given Binary string follows then given condition or not
- Find Excel column name from a given column number
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Restore original String from given Encrypted String by the given operations
- Check if a string can be obtained by rotating another string 2 places
- String slicing in Python to check if a string can become empty by recursive deletion
- Check whether second string can be formed from characters of first string
- Check if a string contains a palindromic sub-string of even length
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Check if a string can be repeated to make another string
- Check if a string can be converted to another string by replacing vowels and consonants
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.