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:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Find the player to last modify a string such that even number of consonants and no vowels are left in the string
- Modify string by removing vowels in between two consonants
- Modify the string by swapping continuous vowels or consonants
- Check if the string contains consecutive letters and each letter occurs exactly once
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Count of sub-strings that contain character X at least once
- Python | Program to accept the strings which contains all vowels
- Program to accept a Strings which contains all the Vowels
- Length of the smallest substring which contains all vowels
- Minimum number of integers required such that each Segment contains at least one of them
- Convert a number of length N such that it contains any one digit at least 'K' times
- Modify the string such that every character gets replaced with the next character in the keyboard
- Find if string is K-Palindrome or not using all characters exactly once
- Arrangement of the characters of a word such that all vowels are at odd places
- Print an N x M matrix such that each row and column has all the vowels in it
- Number of ways to arrange a word such that all vowels occur together
- Maximum number of unique Triplets such that each element is selected only once
- Permutations of string such that no two vowels are adjacent
- Minimum flips required in a binary string such that all K-size substring contains 1
- Replace all consonants with nearest vowels in a string
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.