-
Notifications
You must be signed in to change notification settings - Fork 5
/
Vowel-Substring(HackerRank-Problem Solving Assessment)
119 lines (96 loc) · 2.29 KB
/
Vowel-Substring(HackerRank-Problem Solving Assessment)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'findSubstring' function below.
*
* The function is expected to return a STRING.
* The function accepts following parameters:
* 1. STRING s
* 2. INTEGER k
*/
public static String[] findSubstring(String s, int k) {
// Write your code here
char[] array = s.toCharArray();
int a=0,b=k,previous_C=0;
String previous_W="";
String[] array2 = new String[2];
int c=0;
for(int i=0;i<array.length;i++)
{
if(array[i] == 'a' || array[i] == 'e' || array[i] == 'i' ||
array[i] == 'o' || array[i] == 'u')
{
c++;
break;
}
else
{
if(c!=0)
array2[0] = "Not found!";
}
}
if(c!=0){
while(a!=(array.length-k+1)){
int count=0;
String word = "";
for(int i=a;i<b;i++)
{
if(array[i] == 'a' || array[i] == 'e' || array[i] == 'i' ||
array[i] == 'o' || array[i] == 'u')
{
count++;
}
while(i==0){
previous_C = count;
break;
}
word += ""+array[i];
}
while(a==0){
previous_W = word.toString();
break;
}
a++;
b++;
if(count>previous_C && previous_C !=0)
{
previous_C = count;
previous_W = word.toString();
}
//***
}
}
if(c!=0)
{
array2[0]=previous_W;
}
array2[1]=(String.valueOf(previous_C));
return array2;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
System.gc();
Scanner sc = new Scanner(System.in);
String s =sc.nextLine();
int k = sc.nextInt();
String[] result = Result.findSubstring(s, k);
if(result[0] == null)
{
System.out.println("Not found!");
}else{
System.out.println(result[0]);
}// System.out.println(result[1]);
System.gc();
}
}