Problem:
You are given a randoms string containing only lowercase letters and you need to find if the string contains ALL the vowels.
Input:
First line contains N , the size of the string. Second line contains the letters (only lowercase).
Output:
Print "YES" (without the quotes) if all vowels are found in the string, "NO" (without the quotes) otherwise.
Constraints:
The size of the string will not be greater than 10,000 1 ≤ N ≤ 10000
The above problem is from hackerearth.com and below is my attempt to solve this problem and I need your review on my codestyle, and efficiency and need your help to make it better.
public class TestClass {
public static void main(String[] args) throws IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Length of the String");
final int inputLength = Integer.parseInt(input.readLine());//the size of the string
if (inputLength >= 10000) {
System.err.println("The size of the string can not be greater than 10,000");
System.exit(1);
}
System.out.println("Enter letters");
String word = input.readLine().toLowerCase().trim();
//remove all white space
word = word.replaceAll(" ", "");
final char[] vowels = {'a', 'e', 'i', 'o', 'u'};
short found = 0;
for (final char c : vowels) if (searchForVowel(c, word)) found++;
String result = (found == vowels.length) ? "yes" : "no";
System.out.println(result);
}
private static boolean searchForVowel(char vowel, String word) {
final char[] chars = word.toCharArray();
boolean isContains = false;
for (char c : chars) {
if (c == vowel) {
isContains = true;
break;
}
}
return isContains;
}
}