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, this is always impossible.
For a line longer than 5, this is always possible. Just loop over each character and replace it with a vowel that isn’t on the string. If the current character is a vowel, and if it has not been visited before, then we will not change the character to a vowel. If all vowels are already present at the beginning, then there is no need to change any character.
Below is the implementation of the above approach: