CHOOSN-EDITORIAL

PROBLEM LINK :

Practice
Contest

Author : sneha542
Tester : prasoonjain006
Editorialist : sneha542

DIFFICULTY :

Easy

PREREQUISITES :

Strings

PROBLEM :

A string of english letters is said to be lovely string if it contains all the vowels {a, e, i, o, u} and the count of each vowel is equal.
Example “abeicou” , “aabbeecciivvoouu” , are lovely strings and “aabeiou”, “aabbcc” are not lovely strings.
Given a string of alphabets containing only lowercase aplhabets (a-z), output whether it is a lovely string or not.
Note : Lovely String can also contain letters other than vowels. Read the first statement again !.

QUICK EXPLANATION :

To find whether the string is lovely or not just count all the vowels and check if count of each vowel is equal or not and the string should contain all the vowels.

EXPLANATION :

→ First check if the string contains all vowels or not if in case given string doesn’t contain any vowel then it can’t be considered as lovely string.

→ Now, if the string contains all the vowels then just find out the frequency of each vowel.

→ After counting frequencies just compare that the count of each vowel is same or not.

→ If count of all the vowel is same then the given string is lovely string otherwise it is not a lovely string.

TIME COMPLEXITY :
Time complexity is O(n)

SOLUTIONS :
Editorialist’s Solution

#include <stdio.h>
int main()
{
char string[100];
scanf(“%s”, string);
int a=0,e=0,i=0,o=0,u=0;
for(int j=0; string[j]!=‘\0’; j++){
if(string[j]==‘a’)
a++;
if(string[j]==‘e’)
e++;
if(string[j]==‘i’)
i++;
if(string[j]==‘o’)
o++;
if(string[j]==‘u’)
u++;
}
if(a==0||e==0||i==0||o==0||u==0){
printf(“NotLovely”);
}

else if(a==e && a==i && i==o && o==u){
printf(“LovelyString”);
}
else
printf(“NotLovely”);

return 0;
}

Feel Free to share and discuss your approach here. :smiley:

:+1: