Given a string S containing only Uppercase letters, the task is to find the minimum number of replacement of characters needed to get a string with all vowels and if we cannot make the required string then print Impossible.
Input: str = "ABCDEFGHI" Output: AOUDEFGHI There are already 3 Vowels present in the string A, E, I we just change B and C to O and U respectively. Input: str = "ABC" Output: IMPOSSIBLE
Approach: Since there are only 5 vowels A, E, I, O, U. So, If the string length is less than 5 it is always impossible.
For a string of length greater than equal to 5, it is always possible. Just iterate over each character and replace it with the vowel that doesn’t exists in the string. If the current character is a vowel and if it is not visited earlier then we will not change the character to the vowel. If all the vowels are already present from early then no need to change any character.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Modify string by removing vowels in between two consonants
- Modify the string by swapping continuous vowels or consonants
- Check if a string can be converted to another string by replacing vowels and consonants
- Minimum cost to modify a string
- Modify Numpy array to store an arbitrary length string
- First X vowels from a string
- Reverse vowels in a given string
- Longest Subsequence of a String containing only vowels
- Count the pairs of vowels in the given string
- Permutations of string such that no two vowels are adjacent
- Program to remove vowels from a String
- Remove consecutive vowels from string
- Program to duplicate Vowels in String
- Python | Alternate vowels and consonents in String
- Python | Count and display vowels in a string
- Replace all consonants with nearest vowels in a string
- Check whether the vowels in a string are in alphabetical order or not
- Print reverse string after removing vowels
- Number of words that can be made using exactly P consonants and Q vowels from the given string
- Program to count vowels in a string (Iterative and Recursive)