-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiversity.java
More file actions
36 lines (31 loc) · 1021 Bytes
/
Diversity.java
File metadata and controls
36 lines (31 loc) · 1021 Bytes
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
/**
* Created by MalhotR1 on 12/11/2018.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Diversity {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
char[] in = br.readLine().trim().toCharArray();
int k = Integer.parseInt(br.readLine().trim());
if (k > in.length) {
System.out.println("impossible");
return;
}
Set<Character> set = new HashSet<>();
int count = 0;
for (int i = 0; i < in.length; i++) {
if (!set.contains(in[i])) {
set.add(in[i]);
count++;
}
}
if (count >= k) System.out.println(0);
else System.out.println(k - count);
}
}
}