-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path문자열 게임 2.java
More file actions
56 lines (44 loc) · 1.54 KB
/
문자열 게임 2.java
File metadata and controls
56 lines (44 loc) · 1.54 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
static int[] alpha = new int[26];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for (int i = 0; i < t; i++) {
String line = br.readLine();
int k = Integer.parseInt(br.readLine());
find(line, k);
}
}
static void find(String line, int k) {
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
ArrayList<Integer> [] list = new ArrayList[26];
for (int i = 0; i < 26; i++) {
list[i] = new ArrayList<>();
}
for (int i = 0; i < line.length(); i++) {
list[line.charAt(i) - 'a'].add(i);
}
for (int i = 0; i < 26; i++) {
if (list[i].size() < k) {
continue;
}
for (int j = 0; j <= list[i].size() - k; j++) {
int start = list[i].get(j);
int end = list[i].get(j + k - 1);
int length = end - start + 1;
min = Math.min(min, length);
max = Math.max(max, length);
}
}
if (min == Integer.MAX_VALUE) {
System.out.println(-1);
} else {
System.out.println(min + " " + max);
}
}
}