VOOZH about

URL: https://www.geeksforgeeks.org/dsa/print-the-given-3-string-after-modifying-and-concatenating/

⇱ Print the given 3 string after modifying and concatenating - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Print the given 3 string after modifying and concatenating

Last Updated : 13 Mar, 2023

Given three strings(without spaces). The task is to print the new string after modifying the three given string as follows: 
 

  • Replace all the vowels present in the first string with "*".
  • Don't change anything in the second string.
  • Replace all the consonants in the third string with "$".
  • Concatenate all of the three string to obtain the new string.


Examples: 

Input: how are you
Output\: h*ware$ou

Input: geeks for geeks
Output: g**ksfor$ee$$


 

Approach:
The idea is to traverse the first string and keep checking if any character is a vowel or not. Replace the character in the first string which is vowel with "*". Similarly, traverse the third string and keep checking if any character is not a vowel. If a character in the third string is not a vowel(then it is a consonant), replace it with '$'.
Finally, concatenate the three strings and print the newly concatenated string. 
 

Below is the implementation of the above approach:


Output: 
h*ware$ou

 

Time Complexity: O(m+n), where m is the length of the first string and n is the length of the third string.

Auxiliary Space: O(1), as constant extra space is required.

Comment
Article Tags: