Playing with string consisting of vowels

Playing with String Consisting of vowels

In this page we will discuss the program for playing with string consisting of vowels, the program will then remove vowels a, e, i, o, u (in lower or upper case) from the string. If two vowels are consecutive then we will not removing consecutive vowels, we have to ignore them.
Playing with string consisting of vowels

Method Discussed :

  • Method 1 : Brute Force Approach.
  • Method 2 : By transforming the character in uppercase/lower case.
  • Method 3 : Without using extra space.

Method 1 :

  • Declare a temporary string res to store the required result.
  • Iterate over the string.
  • Check for the every character, if it is a vowel,
  • Then check for next character, if it is vowel then add both character to required string.
  • Otherwise skip that character.
  • At last return string res.

Time and Space Complexity :

  • Time-Complexity : O(n), where n is the length of the input string
  • Space Complexity : O(n) where n is the length of the input string

Output

Welcome to PrepInsta
Wlcm t Prpnst

Put this on Chair
Pt ths n Chr

Method 2 :

In this method we will convert the ith character of the string in either lowercase or uppercase, then we will remove all the vowels except consecutive occurring vowels.

Time and Space Complexity :

  • Time-Complexity : O(n), where n is the length of the input string
  • Space Complexity : O(n) where n is the length of the input string

Output

Welcome to PrepInsta
Wlcm t Prpnst

Put this on Chair
Pt ths n Chr

Method 3 :

In this method we will erase the required elements from the actual string.

Time and Space Complexity :

  • Time-Complexity : O(n), where n is the length of the input string
  • Space Complexity : O(1)

Output

Welcome to PrepInsta
Wlcm t Prpnst

Put this on Chair
Pt ths n Chr

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription