Last Updated: 30 Oct, 2020

Remove Vowels

Easy
Asked in companies
OptumPractoCGI

Problem statement

You are given a string STR of length N. Your task is to remove all the vowels present in that string and print the modified string.

English alphabets ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ are termed as vowels. All other alphabets are called consonants.

Note: You have to only remove vowels from the string. There will be no change in the relative position of all other alphabets.

For example:
(i)  If the input string is 'CodeGeek', the output should be CdGk after removing ‘o’ and ‘e’.

(ii) If the input string is 'Odinson', the output should be 'dnsn' after removing ‘o’ and ‘i’. 
Input Format:
The first line of input contains an integer 'T' representing the number of the test case. Then the test case follows.

The first and only line of each test case contains a string STR of length N.
Output Format:
For each test case, return the modified string that contains ‘NO VOWELS’.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10^4

STR may contain alphabets from 'a' to 'z' or 'A' to 'Z' and blank spaces.

Time Limit: 1 sec 

Approaches

01 Approach

  1. Iterate through the string STR from i = 0 to i = N-1 and check:
    1. If the current character is not vowel: Do nothing.
    2. Else
      1. Iterate from j = i+1 to N-2 and copy j th alphabet to j-1 th position
      2. Reduce the value of N by 1 as an alphabet is removed now.

02 Approach

  1. Create a new empty string, say RES
  2. Iterate through original string STR and check if the current alphabet is a vowel or not.
    1. If it is not a vowel, append it to the back of RES
    2. If it is a vowel do nothing
  3. The RES string now contains the desired string without vowels.