-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaxVowels.java
36 lines (31 loc) · 930 Bytes
/
MaxVowels.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class MaxVowels {
public static void main(String[] args) {
System.out.println(maxVowels("aeiou", 2));
}
public static int maxVowels(String text, int k) {
String vowels = "AEIOUaeiou";
int textLen = text.length();
int count = 0;
int left = 0;
int right = k;
while (right <= textLen) {
int currCount = 0;
for (int j = left; j <= right - 1; j++) {
System.out.print(text.charAt(j));
if (vowels.contains(String.valueOf(text.charAt(j)))) {
currCount++;
}
}
System.out.println();
count = Math.max(currCount, count);
left++;
right++;
}
return count;
}
}